0

I'm making a xml parser for a purpose of challenge. Basically a xml node looks like this:

 public struct XmlTag : IXmlTag
 {
    public IXmlText Name { get; }
    public List<IXmlTag> Children { get; }
    public Attributes Attributes { get; }
    public IXmlText Content { get; }
 }

IXmlText is something, that points into a place in char array.
It worked for some relatively simple xml:

<tag>
  <otherTag/>
</tag>

<tag>String</tag>

But it doesn't work like that for xml

<letter>
  Dear Mr.<name>John Smith</name>.
  Your order <orderid>1032</orderid>
  will be shipped on <shipdate>2001-07-13</shipdate>.   
</letter>

because the tree structure is not suited to contain mixed content, text and other tags.
My question is which tree structure will be good enough to hold both simple text and other text, preserving the exact order of elements?

Andriy Shevchenko
  • 1,117
  • 6
  • 21
  • You're asking for help with software design. I think the response has to be that if you don't know how to design a suitable data structure, then you shouldn't be doing this project, you should be using one of the many excellent XML parsers available off-the-shelf. – Michael Kay Dec 07 '17 at 13:15
  • Thank you, I'm doing this for educational purposes, and not going to produce a most efficient and comprehensive parser – Andriy Shevchenko Dec 07 '17 at 16:20
  • You would get much more educational value by spending a few days studying the source code of a project like JDOM2 which has already done this. (And it would probably give you the answer to your question as well.) – Michael Kay Dec 07 '17 at 16:41

0 Answers0