1
Trying to move export of xmlns="xxxxx" to top level element
Question asked by Scott Zrubek - 6/3/2021 at 8:07 PM
Answered
We currently have this export:

<PT xmlns:xsi="http://blah.org" name="tester1250">
<DTS xmlns=""http://www.aaa.org">
</DTS>
</PT>

I'd like to move the attribute to the top level element to end up with 

<PT xmlns="http://www.aaa.org"  xmlns:xsi="http://blah.org" name="tester1250">
<DTS >
</DTS>
</PT>

If I try

lxWriterSettings.NamespaceMap[""] = namespaceDict["seds"];

I get the following error:

Cannot use a prefix with an empty namespace.

If I try

lxWriterSettings.NamespaceMap["xmlns"] = namespaceDict["seds"];

I get:

Prefix "xmlns" is reserved for use by XML.

2 Replies

Reply to Thread
0
Liquid Support Replied
Employee Post Marked As Answer
Hi,

If you could do what you are attempting, it would produce an invalid XML document.

The element 'PT' is in the 'empty' namespace, the element 'DTS' is in the namespace 'http://www.aaa.org';.

You are trying to set the default namespace to 'http://www.aaa.org'; on the root element 'PT'.

In order for the XML to remain valid you would have to push 'PT' into the 'empty' namespace, something like this xmlns:e="", unfortunately XML does not allow this, you can't push things into the empty namespace. So by adding your default namespace you have effectively pushed 'PT' into the namespace 'http://www.aaa.org';, making the XML document invalid against the schema.

Now if you are trying to minimize the XML document a bit you could add an alias for 'http://www.aaa.org';

lxWriterSettings.NamespaceMap["aaa"] = "http://www.aaa.org";;
The XML would then look like this:
<PT xmlns:aaa="http://www.aaa.org"; name="tester1250">
    <aaa:DTS/>
    <aaa:DTS/>
    <aaa:DTS/>
</PT>
Note: The XML you have posted has other errors the prefix xsi is typically 'http://www.w3.org/2001/XMLSchema-instance'; you have it as xmlns:xsi="http://blah.org";, and as you have extra quotes in <DTS xmlns=""http://www.aaa.org">; I assume you have typed this rather than copied the output from Liquid objects? So the answer I have given is based on guessing your intentions to some extent.

0
Scott Zrubek Replied
Thanks for the clarification!

Yes, my xml was typed as opposed to copied/pasted

Reply to Thread