0

I'm defining an XML schema 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:

  1. for the document without any xmlns declaration, the result should be an empty object;

  2. for the document with mixed xmlns, the result should be a document containing just an element.

user16538
  • 1,080
  • 1
  • 8
  • 17
  • are you really writing your own parser? or are you just writing your own schema? i don't see why you'd need to do your own XML parser – Janus Troelsen Aug 20 '13 at 08:29
  • why not use a [XML Schema (XSD) validation tool?](http://stackoverflow.com/q/124865/309483) – Janus Troelsen Aug 20 '13 at 08:31
  • @JanusTroelsen: I'm writing a schema **and** a parser for it. Of course I'm not writing an XML parser from scratch. – user16538 Aug 20 '13 at 08:32
  • @JanusTroelsen: an XSD validation tool would tell me just if the documents are correct or not. And they are perfectly correct XML documents. This question is not about their format, it's about their meaning. – user16538 Aug 20 '13 at 08:36

0 Answers0