Overview
Features
Download
Documentation
Community
Add-Ons & Services

XML NamePool and XML Document

Please post support and help requests here.

XML NamePool and XML Document

Postby cashnl » 01 Mar 2010, 14:29

Hello,

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);
   pool->insert(name);

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

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


The unexpected output is:
Code: Select all
<root>
        <ns1:child1 xmlns:ns1="http://www.soap-env.com">text1</ns1:child1>
        <child2 xmlns:ns1="http://www.soap-env.com">text2</child2>
</root>


I would expect something like
Code: Select all
<root>
        <soap-env:child1 xmlns:soap-env=http://www.soap-env.com">text1</soap-env:child1>
        <child2>text2</child2>
</root>


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.
cashnl
 
Posts: 3
Joined: 18 Nov 2009, 16:12

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.

Thanks,

-D
dirvin
 
Posts: 3
Joined: 15 May 2012, 20:07


Return to Support

Who is online

Users browsing this forum: bgolenko and 1 guest