473,395 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 26356
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.