Add-Ons & Services

XML NamePool and XML Document

Please post support and help requests here.
Posts: 3
Joined: 18 Nov 2009, 16:12

XML NamePool and XML Document

Postby cashnl » 01 Mar 2010, 14:29


Im trying to setup an XML document with specific namespaces. After setting up the namepool and namespaces I write out the document with the DOMWriter.
The output isn't as expected however.

My Code:

Code: Select all

#include "Poco/DOM/Document.h"
#include "Poco/DOM/Element.h"
#include "Poco/DOM/Text.h"
#include "Poco/DOM/AutoPtr.h"
#include "Poco/DOM/DOMWriter.h"
#include "Poco/XML/XMLWriter.h"
#include <iostream>
#include "Poco/XML/NamePool.h"

using Poco::XML::Document;
using Poco::XML::Element;
using Poco::XML::Text;
using Poco::XML::AutoPtr;
using Poco::XML::DOMWriter;
using Poco::XML::XMLWriter;
using Poco::XML::NamePool;
using Poco::XML::Name;

int main(int argc, char** argv)
   // build a DOM document and write it to standard output.
   std::string ns = "http://www.appinf.com";
   // Setup NamePool
   AutoPtr<NamePool> pool = new NamePool;
   Name name("soap-env", ns);

   // Create Document using the pool and a root element
   AutoPtr<Document> pDoc = new Document(pool);
   AutoPtr<Element> pRoot = pDoc->createElement("root");

   // Append child elements which uses a NS in the NamePool
   AutoPtr<Element> pChild1 = pDoc->createElementNS(ns, "local");
   AutoPtr<Text> pText1 = pDoc->createTextNode("text1");
   // PRint the document
   DOMWriter writer;
   writer.writeNode(std::cout, pDoc);
   return 0;

The unexpected output is:

Code: Select all

        <ns1:child1 xmlns:ns1="http://www.soap-env.com">text1</ns1:child1>
        <child2 xmlns:ns1="http://www.soap-env.com">text2</child2>

I would expect something like

Code: Select all

        <soap-env:child1 xmlns:soap-env=http://www.soap-env.com">text1</soap-env:child1>

My guess is I'm problaly not using the NamePool correct. I dont understand the relation between qualified nam, namespace URI and local name either.

Thanks in advance.

Posts: 6
Joined: 15 May 2012, 20:07

Re: XML NamePool and XML Document

Postby dirvin » 31 May 2013, 23:34

I realize this is an old thread, but did this issue ever have a resolution? I'm seeing essentially the same behavior in 1.4.3p1. I have element nodes with a namespace I want to save to file, but I want to reorganize the namespace names so I don't get ns1, ns2, etc.



Return to “Support”

Who is online

Users browsing this forum: No registered users and 1 guest