需要帮助阻止 MSXML 添加命名空间 [英] Need help stopping MSXML from adding namespaces

查看:27
本文介绍了需要帮助阻止 MSXML 添加命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 MSXML 4 生成以下 xml 字符串:

I am using MSXML 4 to generate the following xml string:

<?xml version="1.0">
<Parent_Element xmlns="http://1">
    <Child_One>
        <Child_Two xmlns="http://2">
            <Child_Three>
            </Child_Three>
        </Child_Two>
    </Child_One>
</Parent>

然而,我的 IXMLDOMDocument2Ptr 的输出总是包含 Child_Three 的命名空间:

However the output from my IXMLDOMDocument2Ptr always includes a namespace for Child_Three:

<?xml version="1.0">
<Parent_Element xmlns="http://1">
    <Child_One>
        <Child_Two xmlns="http://2">
            <Child_Three xmlns="http://1">
            </Child_Three>
        </Child_Two>
    </Child_One>
</Parent>

我的理解是这种行为是 XML 标准的一部分,但是如果存在额外的命名空间,接收 xml 的系统会拒绝它.如果有一个空的命名空间(即 xmlns=""),它也会拒绝 xml.

My understanding is that this behavior is part of the XML standard, but the system receiving the xml rejects it if the extra namespace is present. It will also reject the xml if there is an empty namespace (i.e. xmlns="").

MSXML 中是否有任何方法可以避免添加或删除 Child_Three 的命名空间?

Is there anyway in MSXML to avoid adding or removing the namespace for Child_Three?

推荐答案

我想通了.

1) 我有一个缺陷,即使用文档命名空间而不是父节点中的命名空间.

1) I had a defect where the document namespace was used instead of the namespace in the parent node.

2) 通过 #1 的修复,我最终得到了一个空的命名空间 (xmlns="").为了解决这个问题,我必须在创建节点时设置命名空间.在我创建节点然后在单独的调用中添加 xmlns 属性之前.

2) With the fix from #1, I ended up with an empty namespace (xmlns=""). To corect this I had to set the namepace when the node is created. Before I was creating the node and then added the xmlns attribute in a separate call.

之前:

pNode->createNode(NODE_ELEMENT, name, "");
pAttrib = pNode->createAttribute("xmlns")
pAttrib->put_NodeValue(namespace)

现在:

pNode->createNode(NODE_ELEMENT, name, "namespace");

这篇关于需要帮助阻止 MSXML 添加命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆