Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++的PoCo库,为自定义元素声明命名空间_C++_Poco Libraries - Fatal编程技术网

C++的PoCo库,为自定义元素声明命名空间

C++的PoCo库,为自定义元素声明命名空间,c++,poco-libraries,C++,Poco Libraries,我想通过从头构建DOM文档来创建XML文档,语法如下: AutoPtr<Document> doc = new Document; AutoPtr<Element> root = doc->createElement("root"); doc->appendChild(root); AutoPtr<Element> element1 = doc->createElementNS("http://ns1", "ns1:element1"); r

我想通过从头构建DOM文档来创建XML文档,语法如下:

AutoPtr<Document> doc = new Document;
AutoPtr<Element> root = doc->createElement("root");
doc->appendChild(root);
AutoPtr<Element> element1 = doc->createElementNS("http://ns1", "ns1:element1");
root->appendChild(element1);
AutoPtr<Element> element2 = doc->createElementNS("http://ns1", "ns1:element2");
root->appendChild(element2);

DOMWriter writer;
writer.setNewLine("\n");
writer.setOptions(XMLWriter::PRETTY_PRINT);
writer.writeNode(std::cout, doc);
但是,当我写它时,我得到了下一个结果:

<root>
   <ns1:element1 xmlns:ns1="http://ns1"/>
   <ns1:element2 xmlns:ns1="http://ns1"/>
</root>
名称空间ns1声明了两次,我想在根元素中声明它。 有没有办法获得下一个代表:

<root xmlns:ns1="http://ns1"/>
   <ns1:element1/>
   <ns1:element2/>
</root> 

root->setAttributexmlns:ns1,http://ns1; 或mb root->setAttributeNS,xmlns:ns1,http://ns1; ?不幸的是,它不起作用,尽管我们得到了我目前找到的唯一解决方案-添加一个在此命名空间中声明的伪属性,并在生成字符串表示后删除它。。。但是它太复杂了根->setAttributexmlns:ns1,http://ns1; 或mb root->setAttributeNS,xmlns:ns1,http://ns1; ?不幸的是,它不起作用,尽管我们得到了我目前找到的唯一解决方案-添加一个在此命名空间中声明的伪属性,并在生成字符串表示后删除它。。。但这太棘手了