472,799 Members | 1,265 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,799 software developers and data experts.

Reading XML file using TinyXML

hello,

can you please help me in reading this sample xml using tinyxml library.

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2.  
  3. <Configuration>
  4.     <Parameter name="loglevel" value="3"/>
  5.     <Parameter name="newparam" value="some value"/>
  6.     <Process Name="osis">
  7.         <App ID="1" Name="TATA ADC" LogPath="C:\Projects\TATA\TATA\TATA ADC\Test" SeparatorLine="======">
  8.             <LineFormat Separator="|">
  9.                 <LinePart>Timestamp</LinePart>
  10.                 <LinePart>InformationType</LinePart>
  11.                 <LinePart>Message</LinePart>
  12.             </LineFormat>
  13.             <Block StartKeyword="processing fail"/>
  14.             <Block StartKeyword="processing chain"/>
  15.             <MailRecipient>ABCD@ABC.com</MailRecipient>
  16.         </App>
  17.         <App ID="1" Name="TATA Loader" LogPath="C:\Projects\TATA\TATA\TATA Loader\Test" SeparatorLine="---------">
  18.             <LineFormat Separator="|">
  19.                 <LinePart>Timestamp</LinePart>
  20.                 <LinePart>InformationType</LinePart>
  21.                 <LinePart>Message</LinePart>
  22.                 <LinePart>Detail</LinePart>
  23.                 <LinePart>Location</LinePart>
  24.             </LineFormat>
  25.             <Block StartKeyword="processing"/>
  26.             <MailRecipient>ABCD@ABC.com</MailRecipient>
  27.             <Alert Level="error"/>
  28.         </App>
  29.     </Process>
  30.     <Process Name="Ation">
  31.         <App ID="1" Name="ADA" LogPath="C:\Progloc\ADA" SeparatorLine="">
  32.             <LineFormat Separator=" ">
  33.                 <LinePart>Timestamp</LinePart>
  34.                 <LinePart>Message</LinePart>
  35.             </LineFormat>
  36.             <Block StartKeyword="performing"/>
  37.             <MailRecipient>ABCD@ABC.com</MailRecipient>
  38.         </App>
  39.     </Process>
  40.     <MailServer>smtp.intra.ABC.com</MailServer>
  41.     <MailSender>ABCDE@ABC.com</MailSender>
  42. </Configuration>
It's a bit urgent, please help me now.
Dec 6 '07 #1
9 26251
I've framed in a bit of code to help you process this file. You have a lot in there, so what I gave you should be enough to get you started. I haven't included much cleanup or error handling, just implemented some basic parsing for you.

The output of the following code will look like this:

test.xml loaded
Parameter: name= 'loglevel', value='3'
Parameter: name= 'newparam', value='some value'

Process: osis
..App: ID=1, name=TATA ADC
..App: ID=1, name=TATA Loader
Process: Ation
..App: ID=1, name=ADA


Expand|Select|Wrap|Line Numbers
  1.     // Load the xml file, I put your XML in a file named test.xml
  2.     TiXmlDocument XMLdoc("test.xml");
  3.     bool loadOkay = XMLdoc.LoadFile();
  4.     if (loadOkay)
  5.     {
  6.         cout << "test.xml loaded" << endl;
  7.         TiXmlElement *pRoot, *pParm, *pProcess, *pApp, *pLineFormat;
  8.         pRoot = XMLdoc.FirstChildElement( "Configuration" );
  9.         if ( pRoot )
  10.         {
  11.             // Parse parameters
  12.             pParm = pRoot->FirstChildElement("Parameter");
  13.             while ( pParm )
  14.             {
  15.                 cout << "Parameter: name= '" << pParm->Attribute("name") << "', value='" << pParm->Attribute("value") << "'" << endl;
  16.                 pParm = pParm->NextSiblingElement( "Parameter" );
  17.             }
  18.  
  19.             cout << endl;
  20.  
  21.             // Parse Process 
  22.             pProcess = pRoot->FirstChildElement("Process" );
  23.             while ( pProcess )
  24.             {
  25.                 cout <<"Process: " << pProcess->Attribute("Name" ) << endl;
  26.                 pApp = pProcess->FirstChildElement("App" );
  27.                 while ( pApp )
  28.                 {
  29.                     cout << "..App: ID=" << pApp->Attribute("ID") << ", name=" << pApp->Attribute("Name") << endl;
  30.  
  31.                     // ***************************************************
  32.                     // * TODO: Put code in to handle the App details
  33.                     // ***************************************************
  34.  
  35.                     pApp = pApp->NextSiblingElement("App");
  36.                 }
  37.  
  38.                 pProcess = pProcess->NextSiblingElement("Process");
  39.             }
  40.         }
  41.         else
  42.         {
  43.             cout << "Cannot find 'Configuration' node" << endl;
  44.         }
  45.  
  46.  
I hope this helps
Bill
<removed>
Dec 12 '07 #2
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?> 
  2. <Planning>
  3.     <TwoDobject>
  4.         <Coordinates>
  5.             <Octagonshape>
  6.                 <Firstmodel>
  7.                     <Vertex x="0.000002" y="0.000004" z="0.00"> </Vertex>
  8.                     <Vertex x="0.000002" y="0.000005" z="0.00"> </Vertex>
  9.                     <Vertex x="0.000003" y="0.000006" z="0.00"> </Vertex>
  10.                     <Vertex x="0.000004" y="0.000006" z="0.00"> </Vertex>
  11.                     <Vertex x="0.000005" y="0.000005" z="0.00"> </Vertex>
  12.                     <Vertex x="0.000005" y="0.000004" z="0.00"> </Vertex>
  13.                     <Vertex x="0.000004" y="0.000003" z="0.00"> </Vertex>
  14.                     <Vertex x="0.000003" y="0.000003" z="0.00"> </Vertex>                
  15.                 </Firstmodel>
  16.             </Octagonshape>
  17.             <Rectangleshape>
  18.                 <Firstmodel>
  19.                 </Firstmodel>
  20.             </Rectangleshape>
  21.         </Coordinates>
  22.         <Firstscene>
  23.             <Octagonshape>
  24.                 <Firstmodel>
  25.                 <Transformation x="0.0000035" y="0.0000045" theta=0.0> </Transformation>
  26.                 </Firstmodel>
  27.             </Octagonshape>
  28.             <Rectangleshape>
  29.                 <Firstmodel>
  30.                 </Firstmodel>
  31.             </Rectangleshape>
  32.         </Firstscene>        
  33.     </TwoDobject>
  34.     <ThreeDobject>
  35.     </ThreeDobject>
  36. </Planning>
Hi I have this xml file. I want to parse this . Can anyone help me.
Thanks
Sagar
Sep 30 '09 #3
Dormilich
8,658 Expert Mod 8TB
@sagar353
I can offer help with PHP.
Sep 30 '09 #4
Thanks Dormillich. Actually, I have no experience in PHP. Basically, I want to put all the information in the xml file into a data structure. But I dont know how to do that? Can you help me with some logic.
Sagar
Sep 30 '09 #5
Dormilich
8,658 Expert Mod 8TB
@sagar353
you didn’t say anything about what language you wanted to use. PHP is simply one of the languages I’m good at.
@sagar353
what kind of structure, arrays, objects, …?
Sep 30 '09 #6
Hi Dormilich,
I want to define different classes and objects where I will store the information in a structured way. Thanks
Sagar
Sep 30 '09 #7
Dormilich
8,658 Expert Mod 8TB
you mean something like serialization?

one exchangeable serializer is WDDX…
Sep 30 '09 #8
I dont know what WDDX mean. Since I already organize my XML file, serialization will work probably.
Thanks
Sagar
Sep 30 '09 #9
Dormilich
8,658 Expert Mod 8TB
WDDX is a XML based serializer.
Oct 1 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Tony Stock | last post by:
Hi all, problem - need to read a log (text) file looking for certain entries, this file will still be written to by another 3rd party process, and hence constantly require monitoring (dare I say...
3
by: syntax | last post by:
hi, i want to read a file using fread() in equal chunks through a for loop so that at the last call i dont get error..which way, i should read it? let me give an example, suppose i have 100...
0
by: Pedro Bautista | last post by:
Status: Unsolved and puzzling Steps to reproduce the error: 1.- Delete IUSER from server 2.- Reboot server (OS rebuilds IUSR) 3.- Assign IUSR read and execute permission on web folder and...
4
by: Bill Nguyen | last post by:
I wonder if I can write to an XML file using column structure (and column names) of an SQLserver table. for example: Table A: column1 int column2 char(30) column3 date XML output:
0
Meetee
by: Meetee | last post by:
Hi.. I have created an XML file which contains username and password. I want to parse this XML file so that username and password can be stored in database. I am using TinyXML and want to parse...
3
by: SM | last post by:
Hello, Im trying to access elements in my XML file using the JavaScript DOM but i'm not sure how. I use AJAX to access the XML and then use the responseXML property to access the XML file data. I...
6
by: Studlyami | last post by:
Is it possible to open a file for reading, while another process has it open for writing to it? One of the problems is that the process that is writing to it is written in C and is running on a...
0
by: modykun | last post by:
Reading an XML here is a must for my need I have to say though that i don't have any previous XML experience , so I'm not sure how to make it read it I'm using TinyXML , because i need fast code...
1
by: bjoarn | last post by:
I have an Application C# handling file reading, building index on this file, using dll wrapped with SWIG. The dll is originaly programmed in C++. Dll reports back to the the C# programm throug...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.