Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7433759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:43:25+00:00 2026-05-29T09:43:25+00:00

I have an XML file that looks like this: <?xml version=1.0? encoding=UTF-8 standalone=no?> <dir

  • 0

I have an XML file that looks like this:

<?xml version="1.0"? encoding="UTF-8" standalone="no"?>
<dir name="mint">
  <dir name="pepper">
    <dir name="shauninman">
      <dir name="geomint">
        <file name="readme.txt"/ token="3">
        <file name="blank.gif"/ token="2">
        <file name="class.php"/ token="7"> 
      <dir/>
    <dir/>
  <dir/>
  <dir name="test1">
    <dir name="test2">
      <dir name="test3">
        <file name="foo1.txt"/ token="3">
        <file name="foo2.gif"/ token="5">
        <file name="foo3.php"/ token="5"> 
      <dir/>
      <dir name="test4">
        <file name="foo4.txt"/ token="3">
        <file name="foo5.gif"/ token="5">
        <file name="foo6.php"/ token="5"> 
      <dir/>
    <dir/>
  <dir/>
<dir/>

I once wrote a function in C++ that does a prefix traversal of a tree structure that looks like this:

int traverseTree( Item* node, int id )
{
    cout << id;   
    id = id+1;
    vector<Item*>* children = node->getChildren();

    for( int i = 0; i < children->size(); ++i )
        id = traverseTree( children->at(i), id );

    return id;
}

Now, I want to do the same thing, but from the XML file. In other words, I would like to parse the XML, then send the root to the function “traverseTree”. Then, at each recursive call, I could retrive the children of the current node.

How can I use a tool like xerces to accomplish this? What would be the new function?

Thanks for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:43:25+00:00Added an answer on May 29, 2026 at 9:43 am
    #include <xercesc/parsers/XercesDOMParser.hpp>
    #include <xercesc/dom/DOM.hpp>
    #include <xercesc/sax/HandlerBase.hpp>
    #include <xercesc/util/XMLString.hpp>
    #include <xercesc/util/PlatformUtils.hpp>
    
    #if defined(XERCES_NEW_IOSTREAMS)
    #include <iostream>
    #else
    #include <iostream.h>
    #endif
    
    XERCES_CPP_NAMESPACE_USE
    
    int main (int argc, char* args[]) {
    
        try {
            XMLPlatformUtils::Initialize();
        }
        catch (const XMLException& toCatch) {
            char* message = XMLString::transcode(toCatch.getMessage());
            cout << "Error during initialization!"<< message << "\n";
            XMLString::release(&message);
            return 1;
        }
    
        XercesDOMParser* parser = new XercesDOMParser();
        parser->setValidationScheme(XercesDOMParser::Val_Always);
        parser->setDoNamespaces(true);    // optional
    
        ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
        parser->setErrorHandler(errHandler);
    
        char* xmlFile = "file.xml";
    

    // PARSING —-

        try {
            parser->parse(xmlFile);
        }
        catch (const DOMException& toCatch) {
            char* message = XMLString::transcode(toCatch.msg);
            cout << "Exception message is: \n"
                 << message << "\n";
            XMLString::release(&message);
            return -1;
        }
    

    // GETTING THE DOCUMENT

        DOMDocument* inDoc  = parser->getDocument();
        /* from the document get the pointer to the root */
        DOMNode* inRoot = inDoc->getDocumentElement();
    

    // TRAVERSING

    int traverseTree( DOMNode* node, int id )
    {
    cout << id;   
    id = id+1;
    DOMNodeList* ch_list = node->getChildNodes();
    
    for( int i = 0; i < ch_list->getLength(); ++i )
        id = traverseTree( ch_list->item(i), id );
    
    return id;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML File that looks like this: <?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
I have a simple xml file that looks like this: <?xml version=1.0 encoding=UTF-8 standalone=yes
I have an eclipse's .classpath file that looks like this: <?xml version=1.0 encoding=UTF-8?> <classpath>
I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1
Basically I have an XML file that looks like this: <?xml version=1.0 encoding=UTF-8?> <data>
I have an XML/Soap file that looks like this: <?xml version=1.0 encoding=utf-8?> <soap:Envelope xmlns:soap=http://www.w3.org/2003/05/soap-envelope
I have a xml file, that looks something like this: <?xml version=1.0 encoding=utf-8?> <Settings>
I have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <xs:msgdata xmlns:xs=http://www.myCompany.com
I have to parse an XML document that looks like this: <?xml version=1.0 encoding=UTF-8
I have an xml document that looks something like this <?xml version=1.0 encoding=UTF-8?> <mapPoints>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.