Overview
Features
Download
Documentation
Community
Add-Ons & Services

Getting Element with Domparser

Please post support and help requests here.

Getting Element with Domparser

Postby serhatyilmaz » 12 Jul 2012, 10:04

Hi,
I am trying to get the element from a Document object using Domparser by it seems that the element id is not recognized. How can I get a single element from my XML file using getElementById() method? Thank you for your help in advance.
serhatyilmaz
 
Posts: 3
Joined: 12 Jul 2012, 09:59

Re: Getting Element with Domparser

Postby alex » 12 Jul 2012, 20:29

Code: Select all
#include "Poco/AutoPtr.h"
#include "Poco/DOM/Document.h"
#include "Poco/DOM/Element.h"

using Poco::AutoPtr;
using Poco::XML::Element;
using Poco::XML::Document;

AutoPtr<Document> pDoc = new Document;
pDoc->createElement("root");
pRoot->setAttribute("id", "0");
AutoPtr<Element> pRoot = pDoc->getElementById("0", "id");
alex
 
Posts: 1105
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Getting Element with Domparser

Postby guenter » 12 Jul 2012, 22:24

In other words, your element must have an "id" attribute for getElementById() to work. Alternatively, you can use getNodeByPath().
guenter
 
Posts: 1112
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Getting Element with Domparser

Postby serhatyilmaz » 13 Jul 2012, 10:25

I could create a new Element and add id attribute but I need to read an XML file and get exactly that element in the file.
serhatyilmaz
 
Posts: 3
Joined: 12 Jul 2012, 09:59


Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests