473,386 Members | 1,997 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,386 software developers and data experts.

extract the xml data values in the specified format using C++ code

Hi All,

Please help me in writing the code for extracting the data values from the XML file using C++ code.
The xml file is as follows
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  3.  
  4.   <!-- Configuration Type -->
  5.   <CfgType>
  6.     <Name>Ane Justin</Name>
  7.     <MachineModels>
  8.       <MachineModel>
  9.         <ModelNo>2345678</ModelNo>        
  10.         <MonitorTypes>          
  11.           <MonitorType>
  12.             <MonitorName>17" LCD</MonitorName>          
  13.             <ScreenResolution>
  14.               <Resolution>1024*768</Resolution>
  15.               <RefreshRate>60</RefreshRate>
  16.             </ScreenResolution>            
  17.             <ScreenResolution>
  18.               <Resolution>800*600</Resolution>
  19.               <RefreshRate>60</RefreshRate>
  20.             </ScreenResolution>
  21.           </MonitorType>          
  22.           <MonitorType>
  23.             <MonitorName>19" LCD</MonitorName>            
  24.             <ScreenResolution>
  25.               <Resolution>1024*768</Resolution>
  26.               <RefreshRate>60</RefreshRate>
  27.             </ScreenResolution>            
  28.             <ScreenResolution>
  29.               <Resolution>800*600</Resolution>
  30.               <RefreshRate>60</RefreshRate>
  31.             </ScreenResolution>          
  32.           </MonitorType>          
  33.         </MonitorTypes>        
  34.       </MachineModel>
  35.       <MachineModel>
  36.         <ModelNo>0789456</ModelNo>
  37.         <MonitorTypes>
  38.           <MonitorType>
  39.             <MonitorName>17" CRT</MonitorName>
  40.             <ScreenResolution>
  41.               <Resolution>1024*768</Resolution>
  42.               <RefreshRate>60</RefreshRate>
  43.             </ScreenResolution>
  44.             <ScreenResolution>
  45.               <Resolution>800*600</Resolution>
  46.               <RefreshRate>60</RefreshRate>
  47.             </ScreenResolution>
  48.           </MonitorType>
  49.           <MonitorType>
  50.             <MonitorName>19" CRT</MonitorName>
  51.             <ScreenResolution>
  52.               <Resolution>1024*768</Resolution>
  53.               <RefreshRate>60</RefreshRate>
  54.             </ScreenResolution>
  55.             <ScreenResolution>
  56.               <Resolution>800*600</Resolution>
  57.               <RefreshRate>60</RefreshRate>
  58.             </ScreenResolution>
  59.           </MonitorType>
  60.         </MonitorTypes>
  61.       </MachineModel>
  62.     </MachineModels>
  63.   </CfgType>
  64.  
  65. <CfgType>
  66.     <Name>Jessica Sis</Name>
  67.     <MachineModels>
  68.       <MachineModel>
  69.         <ModelNo>456789</ModelNo>
  70.         <MonitorTypes>
  71.           <MonitorType>
  72.             <MonitorName>17" LCD</MonitorName>
  73.             <ScreenResolution>
  74.               <Resolution>1024*768</Resolution>
  75.               <RefreshRate>60</RefreshRate>
  76.             </ScreenResolution>
  77.             <ScreenResolution>
  78.               <Resolution>800*600</Resolution>
  79.               <RefreshRate>60</RefreshRate>
  80.             </ScreenResolution>
  81.           </MonitorType>
  82.           <MonitorType>
  83.             <MonitorName>19" LCD</MonitorName>
  84.             <ScreenResolution>
  85.               <Resolution>1024*768</Resolution>
  86.               <RefreshRate>60</RefreshRate>
  87.             </ScreenResolution>
  88.             <ScreenResolution>
  89.               <Resolution>800*600</Resolution>
  90.               <RefreshRate>60</RefreshRate>
  91.             </ScreenResolution>
  92.           </MonitorType>
  93.         </MonitorTypes>
  94.       </MachineModel>
  95.       <MachineModel>
  96.         <ModelNo>345678</ModelNo>
  97.         <MonitorTypes>
  98.           <MonitorType>
  99.             <MonitorName>17" CRT</MonitorName>
  100.             <ScreenResolution>
  101.               <Resolution>1024*768</Resolution>
  102.               <RefreshRate>60</RefreshRate>
  103.             </ScreenResolution>
  104.             <ScreenResolution>
  105.               <Resolution>800*600</Resolution>
  106.               <RefreshRate>60</RefreshRate>
  107.             </ScreenResolution>
  108.           </MonitorType>
  109.           <MonitorType>
  110.             <MonitorName>19" CRT</MonitorName>
  111.             <ScreenResolution>
  112.               <Resolution>1024*768</Resolution>
  113.               <RefreshRate>60</RefreshRate>
  114.             </ScreenResolution>
  115.             <ScreenResolution>
  116.               <Resolution>800*600</Resolution>
  117.               <RefreshRate>60</RefreshRate>
  118.             </ScreenResolution>
  119.           </MonitorType>
  120.         </MonitorTypes>
  121.       </MachineModel>
  122.     </MachineModels>
  123.   </CfgType>
  124. </Settings>
  125.  
From the above example xml, we can observe two types of "CfgType"(Ane Justin and Jessica Sis). Under each "CfgType" there are different "MachineModel" and under that "ModelNo" and followed by "ScreenResolution".

Now, the output should be shown as follows on the console window:
Expand|Select|Wrap|Line Numbers
  1. Ane Justin
  2.  
  3.   2345678
  4.     17" LCD
  5.       1024*768
  6.       60
  7.       800*600
  8.       60    
  9.     19" LCD
  10.       1024*768
  11.       60
  12.       800*600
  13.       60
  14.  
  15.   0789456
  16.     17" LCD
  17.       1024*768
  18.       60
  19.       800*600
  20.       60    
  21.     19" LCD
  22.       1024*768
  23.       60
  24.       800*600
  25.       60
  26.  
  27. Jessica Sis
  28.  
  29.   456789
  30.     17" LCD
  31.       1024*768
  32.       60
  33.       800*600
  34.       60    
  35.     19" LCD
  36.       1024*768
  37.       60
  38.       800*600
  39.       60
  40.  
  41.   345678
  42.     17" LCD
  43.       1024*768
  44.       60
  45.       800*600
  46.       60    
  47.     19" LCD
  48.       1024*768
  49.       60
  50.       800*600
  51.       60
  52.  
Could some one please help me in showing the output as show above...
Many Thanks...
Oct 24 '07 #1
1 1909
jkmyoung
2,057 Expert 2GB
One relatively easy way is to use xslt. The xslt file:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
  3.     <xsl:output method="text"/>
  4.     <xsl:variable name="newline">
  5.         <xsl:text>
  6. </xsl:text>
  7.     </xsl:variable>
  8.     <xsl:template match="CfgType">
  9.         <xsl:apply-templates select="Name"/>
  10.         <xsl:value-of select="$newline"/>
  11.         <xsl:apply-templates select="MachineModels/MachineModel"/>
  12.     </xsl:template>
  13.     <xsl:template match="MachineModel">
  14.         <xsl:apply-templates/>
  15.         <xsl:value-of select="$newline"/>
  16.     </xsl:template>
  17.     <xsl:template match="Name">
  18.         <xsl:value-of select="."/>
  19.         <xsl:value-of select="$newline"/>
  20.     </xsl:template>
  21.     <xsl:template match="MonitorType">
  22.         <xsl:apply-templates/>
  23.     </xsl:template>
  24.     <xsl:template match="ModelNo">
  25.         <xsl:text>  </xsl:text><xsl:value-of select="."/>
  26.         <xsl:value-of select="$newline"/>
  27.     </xsl:template>
  28.     <xsl:template match="MonitorName">
  29.         <xsl:text>    </xsl:text><xsl:value-of select="."/>
  30.         <xsl:value-of select="$newline"/>
  31.     </xsl:template>
  32.     <xsl:template match="Resolution|RefreshRate">
  33.         <xsl:text>      </xsl:text><xsl:value-of select="."/>
  34.         <xsl:value-of select="$newline"/>
  35.     </xsl:template>
  36. </xsl:stylesheet>
This file can be run along with your source xml using xalan-c: http://xml.apache.org/xalan-c/
Oct 25 '07 #2

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

Similar topics

8
by: Grant Edwards | last post by:
Perhaps I'm doing something wrong: the struct module docs say it's IEE 754, but I can't figure out how to get it to handle NaN values correctly (either packing or unpacking). >>> x =...
5
by: Chad Richardson | last post by:
Is there a way in SQL Server 2000 to extract data from a table, such that the result is a text file in the format of "Insert Into..." statements, i.e. if the table has 5 rows, the result would be 5...
7
by: fakeprogress | last post by:
For a homework assignment in my Data Structures/C++ class, I have to create the interface and implementation for a class called Book, create objects within the class, and process transactions that...
8
by: HardHackz | last post by:
Is it possible to extract a zip, rar, gzip, tgz, tar, etc. with C++? Thanks in advance, ..::HardHackz::.
0
by: napolpie | last post by:
DISCUSSION IN USER nappie writes: Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file. This file is long file and it's composed by...
3
by: maylee21 | last post by:
hi, anyone can help me figure out how to read data from a text file like this: 10980012907200228082002 and extract the data according to this kind of format: Record type 1 TY-RECORD ...
2
by: clai83 | last post by:
mysql and mysqli functions always return strings values, and I understand that I can set the type of the data via the settype function AFTER I extract the data, but is there a way with PHP to extract...
7
by: JoeC | last post by:
I am trying to create a windows program that reads binary graphics as a resource. This has nothing to do with win32 but conversion of data with memcpy. graphic::graphic(UINT uiResID, HINSTANCE...
1
by: sausthav | last post by:
Hi All, I am unable to get the excel open when user select two dates from my code. Previously i was successfully extracting values by selecting year and month values from the webpage. Could you help...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.