File Data Extraction Help

I have the following data in a text file that I need to input into a program. The program needs to output another text file containing only the timestamps and the power wattage values...

Text file data
---------------------------------------------------------
<MTConnectStreams xmlns:m="urn:mtconnect.org:MTConnectStreams:1.2" xmlns="urn:mtconnect.org:MTConnectStreams:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mtconnect.org:MTConnectStreams:1.2 http://www.mtconnect.org/schemas/MTConnectStreams_1.2.xsd">
<Header creationTime="2014-07-08T18:14:18Z" sender="lab-PC" instanceId="1396368889" version="1.2.0.23" bufferSize="524288" nextSequence="121794222" firstSequence="121269934" lastSequence="121794221"/>
<Streams>
<DeviceStream name="mori_nvd_1500" uuid="mori_nvd_1500">
<ComponentStream component="Rotary" name="C" componentId="C_23">
<Samples>
<SpindleSpeed dataItemId="C_24" timestamp="2014-07-08T18:13:40.837Z" name="S1speed" sequence="121792789">2500</SpindleSpeed>
<Load dataItemId="C_25" timestamp="2014-07-08T18:14:16.468Z" name="S1load" sequence="121794143">27</Load>
</Samples>
<Events>
<RotaryMode dataItemId="C_26" timestamp="2014-04-01T16:14:49.365Z" sequence="3">SPINDLE</RotaryMode>
</Events>
<Condition>
<Normal dataItemId="C_27" timestamp="2014-06-10T20:34:15.909Z" name="S1servo" sequence="118799290" type="LOAD"/>
</Condition>
</ComponentStream>
<ComponentStream component="Linear" name="X" componentId="X_5">
<Samples>
<Position dataItemId="X_6" timestamp="2014-07-08T18:14:18.558Z" name="Xact" sequence="121794218" subType="ACTUAL">-8.28686</Position>
<Load dataItemId="X_7" timestamp="2014-07-08T18:14:18.558Z" name="Xload" sequence="121794219">71</Load>
</Samples>
<Condition>
<Normal dataItemId="X_10" timestamp="2014-06-10T20:34:15.909Z" name="Xservo" sequence="118799283" type="LOAD"/>
<Normal dataItemId="X_8" timestamp="2014-06-10T20:34:15.909Z" name="Xtravel" sequence="118799281" type="POSITION"/>
<Normal dataItemId="X_9" timestamp="2014-06-10T20:34:15.909Z" name="Xoverheat" sequence="118799282" type="TEMPERATURE"/>
</Condition>
</ComponentStream>
<ComponentStream component="Linear" name="Y" componentId="Y_11">
<Samples>
<Position dataItemId="Y_12" timestamp="2014-07-08T18:14:02.724Z" name="Yact" sequence="121793629" subType="ACTUAL">-16.8377</Position>
<Load dataItemId="Y_13" timestamp="2014-07-08T18:14:18.558Z" name="Yload" sequence="121794220">9</Load>
</Samples>
<Condition>
<Normal dataItemId="Y_14" timestamp="2014-06-10T20:34:15.909Z" name="Ytravel" sequence="118799284" type="POSITION"/>
<Normal dataItemId="Y_15" timestamp="2014-06-10T20:34:15.909Z" name="Yoverheat" sequence="118799285" type="TEMPERATURE"/>
<Normal dataItemId="Y_16" timestamp="2014-06-10T20:34:15.909Z" name="Yservo" sequence="118799286" type="LOAD"/>
</Condition>
</ComponentStream>
<ComponentStream component="Linear" name="Z" componentId="Z_17">
<Samples>
<Position dataItemId="Z_18" timestamp="2014-07-08T18:06:38.655Z" name="Zact" sequence="121777321" subType="ACTUAL">-15.52957</Position>
<Load dataItemId="Z_19" timestamp="2014-07-08T18:14:18.558Z" name="Zload" sequence="121794221">14</Load>
</Samples>
<Condition>
<Normal dataItemId="Z_20" timestamp="2014-06-10T20:34:15.909Z" name="Ztravel" sequence="118799287" type="POSITION"/>
<Normal dataItemId="Z_21" timestamp="2014-06-10T20:34:15.909Z" name="Zoverheat" sequence="118799288" type="TEMPERATURE"/>
<Normal dataItemId="Z_22" timestamp="2014-06-10T20:34:15.909Z" name="Zservo" sequence="118799289" type="LOAD"/>
</Condition>
</ComponentStream>
<ComponentStream component="Controller" name="controller" componentId="controller_28">
<Samples>
<PathFeedrate dataItemId="controller_30" timestamp="2014-07-08T17:55:26.778Z" name="Fovr" sequence="121760940" subType="OVERRIDE">100</PathFeedrate>
<SpindleSpeed dataItemId="controller_31" timestamp="2014-06-10T20:34:16.253Z" name="SspeedOvr" sequence="118799293" subType="OVERRIDE">100</SpindleSpeed>
</Samples>
<Events>
<Message dataItemId="controller_29" timestamp="2014-06-10T20:34:16.237Z" name="message" sequence="118799291">
EX4002 &#x11E;&#177; &#166; &#178;&#x44;&#x7A0;&#182;&#178;&#x372; &#188;&#xF8;&#192;&#x7BB;&#178; OPEN DOOR THEN CLOSE APRIRE E CHIUDERE LA PORTA ABRIR/CERRAR PUERTA TUER OEFFNEN,DANN SCHLIESSEN OUVRIR LA PORTE PUIS LA FERMER
</Message>
</Events>
</ComponentStream>
<ComponentStream component="Electric" name="electric" componentId="electric_51">
<Samples>
<AmperageTimeSeries dataItemId="electric_52" timestamp="2014-04-01T16:14:49.365Z" name="Ia" sequence="25" sampleCount="">UNAVAILABLE</AmperageTimeSeries>
<AmperageTimeSeries dataItemId="electric_53" timestamp="2014-04-01T16:14:49.365Z" name="Ib" sequence="26" sampleCount="">UNAVAILABLE</AmperageTimeSeries>
<AmperageTimeSeries dataItemId="electric_54" timestamp="2014-04-01T16:14:49.365Z" name="Ic" sequence="27" sampleCount="">UNAVAILABLE</AmperageTimeSeries>
<VoltageTimeSeries dataItemId="electric_55" timestamp="2014-04-01T16:14:49.365Z" name="Va" sequence="28" sampleCount="">UNAVAILABLE</VoltageTimeSeries>
<VoltageTimeSeries dataItemId="electric_56" timestamp="2014-04-01T16:14:49.365Z" name="Vb" sequence="29" sampleCount="">UNAVAILABLE</VoltageTimeSeries>
<VoltageTimeSeries dataItemId="electric_57" timestamp="2014-04-01T16:14:49.365Z" name="Vc" sequence="30" sampleCount="">UNAVAILABLE</VoltageTimeSeries>
<VoltAmpereTimeSeries dataItemId="electric_58" timestamp="2014-04-01T16:14:49.365Z" name="kva_a" sequence="31" sampleCount="">UNAVAILABLE</VoltAmpereTimeSeries>
<VoltAmpereTimeSeries dataItemId="electric_59" timestamp="2014-04-01T16:14:49.365Z" name="kva_b" sequence="32" sampleCount="">UNAVAILABLE</VoltAmpereTimeSeries>
<VoltAmpereTimeSeries dataItemId="electric_60" timestamp="2014-04-01T16:14:49.365Z" name="kva_c" sequence="33" sampleCount="">UNAVAILABLE</VoltAmpereTimeSeries>
<VoltAmpereReactiveTimeSeries dataItemId="electric_61" timestamp="2014-07-08T18:14:17.716Z" name="kvar_a" sequence="121794208" sampleCount="25">
3937 3938 3940 3944 3943 3943 3939 3937 3937 3931 3925 3921 3919 3920 3918 3918 3920 3922 3919 3915 3913 3910 3907 3904 3899
</VoltAmpereReactiveTimeSeries>
<VoltAmpereReactiveTimeSeries dataItemId="electric_62" timestamp="2014-07-08T18:14:17.716Z" name="kvar_b" sequence="121794204" sampleCount="25">
5805 5805 5807 5807 5806 5803 5801 5797 5794 5790 5786 5784 5781 5780 5777 5776 5779 5779 5784 5789 5794 5800 5803 5807 5808
</VoltAmpereReactiveTimeSeries>
<VoltAmpereReactiveTimeSeries dataItemId="electric_63" timestamp="2014-07-08T18:14:17.716Z" name="kvar_c" sequence="121794206" sampleCount="25">
7128 7134 7136 7136 7143 7141 7141 7141 7140 7143 7142 7144 7143 7147 7154 7155 7158 7159 7161 7162 7160 7163 7163 7166 7170
</VoltAmpereReactiveTimeSeries>
<WattageTimeSeries dataItemId="electric_64" timestamp="2014-07-08T18:14:17.716Z" name="kw_a" sequence="121794207" sampleCount="25">
19437 19430 19416 19414 19423 19429 19426 19420 19421 19435 19440 19425 19414 19409 19413 19420 19412 19407 19414 19423 19439 19440 19434 19441 19455
</WattageTimeSeries>
<WattageTimeSeries dataItemId="electric_65" timestamp="2014-07-08T18:14:17.716Z" name="kw_b" sequence="121794209" sampleCount="25">
8795 8792 8794 8801 8804 8800 8802 8805 8810 8810 8801 8793 8795 8798 8796 8790 8784 8789 8797 8798 8796 8797 8805 8815 8818
</WattageTimeSeries>
<WattageTimeSeries dataItemId="electric_66" timestamp="2014-07-08T18:14:17.716Z" name="kw_c" sequence="121794205" sampleCount="25">
12572 12579 12585 12584 12581 12591 12602 12602 12598 12596 12593 12601 12596 12588 12596 12599 12609 12616 12612 12618 12629 12636 12637 12629 12623

----------------------------------------------------------------------------

I mocked up a quick code to start,at least to get the timestamps, but I am not getting the proper output. Any help is much appreciated...

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
ifstream inFile;
string tempString;
ofstream outFile;

inFile.open ("log.txt");
outFile.open ("timestamp.txt");

if (!inFile)
{
cout << "Failed to open file'" << endl; //error message
}

while (inFile)
{
inFile >> tempString;

if(tempString.find('time') != string::npos)
{
outFile << tempString;
break;
}

}

{
outFile << "Time Stamps: \n";
inFile.close();
outFile.close();

cin.get();
system("pause");
return 0;
}
}


Topic archived. No new replies allowed.