Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XercesDomParser

XercesDomParser

Scheduled Pinned Locked Moved XML / XSL
c++xmljsonperformancetutorial
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VVVimal
    wrote on last edited by
    #1

    Hi i had been using XercersDomParser for parsing the XML file in C++ I am not familiar with XML. In the follwing XML file <?xml version="1.0" encoding="UTF-8"?> <Locomotives> <Locomotive xmlns="http://localhost:8080/source/schemas/locomotive.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://localhost:8080/source/schemas/locomotive.xsd http://localhost:8080/source/schemas/locomotive.xsd"> <LocoId>9001</LocoId> <LocoRunNumber>UnReg</LocoRunNumber> <LocomotiveGPSData> <SampleTime>2008-07-13T13:37:33</SampleTime> <Latitude>-32.86693333</Latitude> <Longitude>151.75333333</Longitude> <Speed>-1</Speed> <Direction>-1</Direction> <KmPostPosition>178500</KmPostPosition> <TrackNumber>85</TrackNumber> </LocomotiveGPSData> <Events> <Alarms>0</Alarms> <Faults>0</Faults> </Events> </Locomotive> <Locomotive xmlns="http://localhost:8080/source/schemas/locomotive.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://localhost:8080/source/schemas/locomotive.xsd http://localhost:8080/source/schemas/locomotive.xsd"> <LocoId>9002</LocoId> <LocoRunNumber>UnReg</LocoRunNumber> <LocomotiveGPSData> <SampleTime>2008-07-13T23:59:56</SampleTime> <Latitude>-32.61888333</Latitude> <Longitude>151.14988333</Longitude> <Speed>-1</Speed> <Direction>-1</Direction> <KmPostPosition>239000</KmPostPosition> <TrackNumber>87</TrackNumber> </LocomotiveGPSData> <Events> <Alarms>0</Alarms> <Faults>0</Faults> </Events> </Locomotives> Eventhough i can traverse through XML file through DOMTreeWalker but can't get idea to store Values in a strucured <list> the structure look like this typedef struct { Loco_Id LocoId ; string /*DateTime*/ SampleTime ; float Lattitude; float Longitude; float Speed ; float Direction; int KmPostPosition; int TrackNumber; int Alarms; int Failures ; }LocoDetails Can any one tell how to access the value from the XML file and store to a list

    S 1 Reply Last reply
    0
    • V VVVimal

      Hi i had been using XercersDomParser for parsing the XML file in C++ I am not familiar with XML. In the follwing XML file <?xml version="1.0" encoding="UTF-8"?> <Locomotives> <Locomotive xmlns="http://localhost:8080/source/schemas/locomotive.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://localhost:8080/source/schemas/locomotive.xsd http://localhost:8080/source/schemas/locomotive.xsd"> <LocoId>9001</LocoId> <LocoRunNumber>UnReg</LocoRunNumber> <LocomotiveGPSData> <SampleTime>2008-07-13T13:37:33</SampleTime> <Latitude>-32.86693333</Latitude> <Longitude>151.75333333</Longitude> <Speed>-1</Speed> <Direction>-1</Direction> <KmPostPosition>178500</KmPostPosition> <TrackNumber>85</TrackNumber> </LocomotiveGPSData> <Events> <Alarms>0</Alarms> <Faults>0</Faults> </Events> </Locomotive> <Locomotive xmlns="http://localhost:8080/source/schemas/locomotive.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://localhost:8080/source/schemas/locomotive.xsd http://localhost:8080/source/schemas/locomotive.xsd"> <LocoId>9002</LocoId> <LocoRunNumber>UnReg</LocoRunNumber> <LocomotiveGPSData> <SampleTime>2008-07-13T23:59:56</SampleTime> <Latitude>-32.61888333</Latitude> <Longitude>151.14988333</Longitude> <Speed>-1</Speed> <Direction>-1</Direction> <KmPostPosition>239000</KmPostPosition> <TrackNumber>87</TrackNumber> </LocomotiveGPSData> <Events> <Alarms>0</Alarms> <Faults>0</Faults> </Events> </Locomotives> Eventhough i can traverse through XML file through DOMTreeWalker but can't get idea to store Values in a strucured <list> the structure look like this typedef struct { Loco_Id LocoId ; string /*DateTime*/ SampleTime ; float Lattitude; float Longitude; float Speed ; float Direction; int KmPostPosition; int TrackNumber; int Alarms; int Failures ; }LocoDetails Can any one tell how to access the value from the XML file and store to a list

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      There are a lot of ways to do it - here's some suggestions:

      • The DOMTreeWalker lets you set up a node filter. You can set up a filter to accept all element nodes whose tag is Locomotive. That means that each call to the DOMTreeWalker's nextNode method will step to the next Locomotive element. For each of these, you iterate through the found element's child nodes. Each child's tag name indicates which struct memeber they relate to, while the child's text node is the value that you'll convert to the correct type using string conversion functions like strtol.
      • From the root node, apply an XPath of "//Locomotive". That'll get you all the Locomotive elements, which you can process as above.
      • Get a DOMElement for the root element of the XML document. Use the getElementsByTagName method to retrieve all descendent nodes with the tag naem Locomotive. Process each node as indicated above.

      Hope that helps you!

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      V 2 Replies Last reply
      0
      • S Stuart Dootson

        There are a lot of ways to do it - here's some suggestions:

        • The DOMTreeWalker lets you set up a node filter. You can set up a filter to accept all element nodes whose tag is Locomotive. That means that each call to the DOMTreeWalker's nextNode method will step to the next Locomotive element. For each of these, you iterate through the found element's child nodes. Each child's tag name indicates which struct memeber they relate to, while the child's text node is the value that you'll convert to the correct type using string conversion functions like strtol.
        • From the root node, apply an XPath of "//Locomotive". That'll get you all the Locomotive elements, which you can process as above.
        • Get a DOMElement for the root element of the XML document. Use the getElementsByTagName method to retrieve all descendent nodes with the tag naem Locomotive. Process each node as indicated above.

        Hope that helps you!

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        V Offline
        V Offline
        VVVimal
        wrote on last edited by
        #3

        But still i am finding difficulty could you please give me a example...............

        S 1 Reply Last reply
        0
        • V VVVimal

          But still i am finding difficulty could you please give me a example...............

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          VVVimal wrote:

          could you please give me a example

          This[^] indicates this sample[^] which may be helpful, as well as many other pages.

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          1 Reply Last reply
          0
          • S Stuart Dootson

            There are a lot of ways to do it - here's some suggestions:

            • The DOMTreeWalker lets you set up a node filter. You can set up a filter to accept all element nodes whose tag is Locomotive. That means that each call to the DOMTreeWalker's nextNode method will step to the next Locomotive element. For each of these, you iterate through the found element's child nodes. Each child's tag name indicates which struct memeber they relate to, while the child's text node is the value that you'll convert to the correct type using string conversion functions like strtol.
            • From the root node, apply an XPath of "//Locomotive". That'll get you all the Locomotive elements, which you can process as above.
            • Get a DOMElement for the root element of the XML document. Use the getElementsByTagName method to retrieve all descendent nodes with the tag naem Locomotive. Process each node as indicated above.

            Hope that helps you!

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            V Offline
            V Offline
            VVVimal
            wrote on last edited by
            #5

            DOMElement* elementRoot = domDocumet->getDocumentElement(); DOMTreeWalker *walker =domDocumet->createTreeWalker(elementRoot,DOMNodeFilter::SHOW_ELEMENT,NULL, true); DOMNode *pCurrent = NULL; for ( pCurrent = walker->getCurrentNode();pCurrent != 0; pCurrent = walker->nextNode() ) { if(pCurrent->getNodeType() == DOMNode::ELEMENT_NODE) { char *str = XMLString::transcode(pCurrent->getNodeName()); if(!strcmp(str,"LocoId")) int i=0; //myDetails->LocoId = XMLString::transcode(text->getNodeValue()); if(!strcmp(str,"Latitude")) //myDetails->Lattitude = XMLString::transcode(text->getNodeValue()); XMLString::release(&str); } } Could you please tell me where to set the filter as Locomotive you also mentioned "From the root node, apply an XPath of "//Locomotive " what does it mean Thanks you also mentioned as

            S 1 Reply Last reply
            0
            • V VVVimal

              DOMElement* elementRoot = domDocumet->getDocumentElement(); DOMTreeWalker *walker =domDocumet->createTreeWalker(elementRoot,DOMNodeFilter::SHOW_ELEMENT,NULL, true); DOMNode *pCurrent = NULL; for ( pCurrent = walker->getCurrentNode();pCurrent != 0; pCurrent = walker->nextNode() ) { if(pCurrent->getNodeType() == DOMNode::ELEMENT_NODE) { char *str = XMLString::transcode(pCurrent->getNodeName()); if(!strcmp(str,"LocoId")) int i=0; //myDetails->LocoId = XMLString::transcode(text->getNodeValue()); if(!strcmp(str,"Latitude")) //myDetails->Lattitude = XMLString::transcode(text->getNodeValue()); XMLString::release(&str); } } Could you please tell me where to set the filter as Locomotive you also mentioned "From the root node, apply an XPath of "//Locomotive " what does it mean Thanks you also mentioned as

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              Set the filter in the createTreeWalker method call.

              VVVimal wrote:

              you also mentioned "From the root node, apply an XPath of "//Locomotive " what does it mean

              Using an XPath[^] library such as Xalan[^] or XQilla[^], you apply an XPath evaluator class to the DOM. That will give you an iterator that'll go through the nodes that match the XPath expression you gave to the XPath evaluator. Read up on XPath - it's a very useful tool to know how to use.

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups