tags:

views:

148

answers:

2

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

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

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

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

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="").

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

A: 

MSXML will represent exactly the namespaces you tell it to represent.

From your quotation, it looks as if you created the child3 node with a namespace of http://1, and you need to create it with a namespace of http://2.

bmargulies
I tried that and I get the following:<?xml version="1.0"><Parent_Element xmlns="http://1"> <Child_One> <Child_Two xmlns="http://2"> <Child_Three xmlns="http://2"> </Child_Three> </Child_Two> </Child_One></Parent>The issue is that the namespace is included in the output. Whatever he namespace is, I cannot include it in the output.
TERACytE
You need to post code. However, no valid XML reader is allowed to reject that 'excess' namespace.
bmargulies
A: 

I figured it out.

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

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.

Before:

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

Now:

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