How to iterate through an xml file if only the root node is provided

111 Views Asked by At

In a complex C++ program, which is using Xerces, I have to iterate through XML files, and I have to modify its tags.

One of the simpliest XML file looks like this:

<?xml version="1.0" encoding="ISO-8859-2"?>
<?xml-stylesheet type="text/xsl" href="http://specificSite/something.xslt"?>
<RootNode xmlns="http://specificSite#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="specific_site# http://specificsite.com/something.xsd">
 <Node>
  <Title>
   <Item1>aaa</Item1>
   <Item2>bbb</Item2>
     <SubTitle>
       <Item4>555</Item4>
       <Item5>333</Item5>
     </SubTitle>
   </Title>
  </Node>
</Root>

The program read the chosen XML file. At the specific point, where I have to write my code, I got the root node of this XML file, which type is an XMLNode* The root node can have child nodes, those child nodes can have another child nodes, etc (as you can see in the sample XML file).

How should I iterate through the whole XML file and modify each xml tag? I wrote a recursive function it not worked. I am planning to apply visitor design pattern, but I am not so familiar with this. All in all the biggest problem is that, I only can use the root node of the XML.

0

There are 0 best solutions below