Tuesday, 20 August 2013

Should my parser require an XML namespace?

Should my parser require an XML namespace?

I'm defining an XML format and writing a parser for it. This is perfectly
legitimate:
<?xml version="1.0"?>
<a:root xmlns:a="http://somewhere/a/">
<a:element/>
<a:element/>
<a:element/>
</a:root>
However I have doubts about the following two documents:
<?xml version="1.0"?>
<root>
<element/>
<element/>
<element/>
</root>
and
<?xml version="1.0"?>
<a:root xmlns:a="http://somewhere/a/" xmlns:b="http://somewhere/b/">
<a:element/>
<b:element/>
<element/>
<element/>
</a:root>
If I give these two documents to my parser, what should the results be? Is
there something like a w3 recommendation on this topic?



For your interest, here is what I though:
for the document without any xmlns declaration, the result should be an
empty object;
for the document with mixed xmlns, the result should be a document
containing just an element.

No comments:

Post a Comment