Overview
Features
Download
Documentation
Community
Add-Ons & Services

[XML] DOM Parser code: it is ok but not print the node value

A general discussion forum.

[XML] DOM Parser code: it is ok but not print the node value

Postby takeokikuta » 06 May 2010, 10:28

I wrote the follow code.
It's ok but not print the node value.
I don't understand.
What is my error? Thanks

Code: Select all
#include <stdlib.h>
#include <iostream>
#include <Poco/XML/XMLString.h>
#include <Poco/DOM/Document.h>
#include <Poco/DOM/Node.h>
#include <Poco/DOM/NodeList.h>
#include <Poco/DOM/DOMParser.h>

using namespace std;

int main(int argc, char** argv) {

    Poco::XML::DOMParser *domParser = new Poco::XML::DOMParser();
    Poco::XML::Document *doc = NULL;
    Poco::XML::Node *node = NULL;
    Poco::XML::NodeList *nodeList = NULL;
   
    Poco::XML::XMLString *iFile = new Poco::XML::XMLString("book.xml");
    Poco::XML::XMLString *tagTitle = new Poco::XML::XMLString("title");
   
    doc = domParser->parse(*iFile);
    nodeList = doc->getElementsByTagName(*tagTitle);
    node = nodeList->item(0);
   
    cout << node->nodeName() << ": " << node->nodeValue() << endl;
   
    return (EXIT_SUCCESS);
}


Xml file is:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE books SYSTEM "book.dtd">
<books>
    <book>
        <title><![CDATA[L'eretico]]></title>
    </book>
</books>


DTD file is:

Code: Select all
<?xml version='1.0' encoding='UTF-8'?>
<!ELEMENT books (book)*>
<!ELEMENT book (title)*>
<!ELEMENT title (#PCDATA)>
takeokikuta
 
Posts: 4
Joined: 20 Apr 2010, 16:47

Re: [XML] DOM Parser code: it is ok but not print the node value

Postby guenter » 07 May 2010, 09:24

nodeValue() does not give you the content of an Element. You can use innerText() (which is not part of the standard DOM, but a POCO extension) instead of nodeValue().

PS: You might also want to think about the excessive, but unnecessary use of new in your code...
guenter
 
Posts: 1138
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: [XML] DOM Parser code: it is ok but not print the node value

Postby takeokikuta » 07 May 2010, 15:08

:D ...Ok thanks
takeokikuta
 
Posts: 4
Joined: 20 Apr 2010, 16:47


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron