使用 pugixml 将 xml 命名空间添加到xml_document
Add xml namespace to xml_document using pugixml
如何使用pugixml将xml namespace
声明添加到我的xml_document
中?
我试过这个,这导致了无效的 xml(无效的字符":",我的验证器说(:
xml_document doc;
auto declarationNode = doc.append_child(node_declaration);
declarationNode.append_attribute("xmlns:xsi") = "http://www.w3.org/2001/XMLSchema-instance";
我想命名空间声明与 xml 属性不同。
但是如何添加该命名空间声明呢?
我引用了 pugixml 的创建者zeux,他非常友好地在 github 上回答了这个问题。
此代码将 xmlns 属性追加到节点;您应该 改为将其附加到文档元素:
doc.document_element().append_attribute("xmlns:xsi") = "http://www.w3.org/2001/XMLSchema-instance";
我注意到的代码将属性添加到"rootnode"元素,因此 必须在将根节点添加到文档后运行。
相关文章:
- Cppcheck生成xml转储文件
- 如何在pugixml中获取节点的内部XML
- 如何使用tinyxml2从XML加载父实体和子实体
- boost xml parsingl将xml的路径作为变量发送
- C++RapidXml-使用first_node()遍历以修改XML文件中节点的值
- 使用 Tinyxml 在 xml 中添加一个子子项
- 增强基于 XML class_id的反序列化
- 在 c++ 中使用 vtd-xml 时,如何摆脱 EOFException?
- 防止在C++中选择错误文件时提升 xml 解析器崩溃
- c++ 读取 xml 文件的内容
- 删除 XML 文件中的子节点C++
- 使用 RapidXML 更新C++中的 XML 节点和属性值
- 在Cmake构建CmakeList.txt中读取/解析XML文件
- 从 XML 中读取未指定结构的每个数据成员
- XML to XML XSLT transformation. MSXML in VBScript
- 将 QGraphicsView 或 Scene 转换为 XML/JSON
- Qt 写入 xml: QIODevice::write (QFile, "D:/logs.xml" ): 设备未打开
- 使用 libxml2 解析 XML 文件时缺少元素值
- 为什么TinyXML2的XMLDocument::FirstChild()函数在尝试解析这个有效的XML文件时返回NULL?
- bsoncxx: document::view vs document::value