XML parser (format specific)

Hey there,

Consider the following XML formats:

Format 1:

<Player>
    <name>Alex</name>
    <Position>
        <x>1</x>
        <y>1</y>
        <z>1</z>
    </Position>
</Player>

Format 2:

<Player name="alex">
    <Position x="1" y="1" z="1"/>
</Player>

Both of these XML documents have the same hierarchical structure, they’re just in different formats right?

Okay having said that, I found an XML parser on this forum that can parse Format 1. I also found an XML parser that can parse Format 2.

I have a program that can convert flow charts into XML documents. But the format is different from the above two:

Format 3:

<Player name="alex">
     <Position>
          <x>1</x>
          <y>1</y>
          <z>1</z>
     </Position>
</Player>

Its a mix between format 1 and format 2. Does anyone know of any existing XML parsers that can parse Format 3?

Possible solutions I have to my problem are:

  • Write/Find a parser that’s compatible with Format 3
  • Write a program that can convert Format 3 documents into Format 1 or Format 2 and use an existing parser.

How hard is it to write an XML parser? I understand what the purpose of encoding/decoding and serialization/deserialization is, but I do not understand how it works. I also do not know what the difference is between UTF-8 and UTF-16 is. Something to do with byte size?

I’m open to all suggestions. For learning purposes, I’ve looked at the scripting for both parsers I already have, but its hard following along as there is no documentation for the code. If anyone has a step by step tutorial on writing any general xml parser, or if you have any reference links, please share them!

Also, do you think this would be more efficient than creating a program that converts between XML formats?

Alex

Any XML parser should be able to parse all valid XML formats. It is more a matter of the code you need to write to extract what you want from the parsed data.

There is a Unity-friendly XML parser here which turns XML data into a Hashtable representation. You just need to look up the appropriate data from the tables to reconstruct the stored data.

Only read?