- Home /
Parse xml with unknown fields
I'm working on Tiled parser to Unity. In Tiled, it is possibble to add objects to the level (they are stored in xml format). I'm looking for a possibility to add any property to the object, so it can be read and used in Unity.
For example, i'm adding object with name Apple, script would search for Apple prefab (easy part) and create it. Next, i can add some fields and values in Tiled. What i'm looking for is a way how to parse and send them to Unity prefab. Say, i can agree that prefab should have the same name as main script (so far so good).
Actually, it is a process of deserializing object from xml.
PS: just during writing of this question, i got an idea that i can inherit all parsable prefabs script components from some base class, and use its method for sending parsed fields. But the main part of the question is still there: how to parse unknown xml?
Answer by perchik · Aug 26, 2013 at 02:40 PM
Simply put--- you can't. If you know absolutely nothing about the XML there is no way to parse it.
Now, with that said, it sounds like the XML is being generated with some format. Perhaps something like
<Object name>
<property 1>
<property 2>
</object name>
<Object name>
<property 1>
</object name>
in which case, you may not know exactly how many properties it has, but it has some fixed format. I'd suggest trying to figure out what that format is and which pieces are optional. Then parse that general format.
Well, i know the whole structure of xaml. I don't know how to send those properties to custom script component.
Say, i'm adding object with name "door", set property "Id" to "101" and "Description" to "Just a common door".
<object name="door" type="first" gid="1" x="1664" y="1408">
<properties>
<property name="Description" value="Just a common door"/>
<property name="Id" value="101"/>
</properties>
</object>
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
XML parsing c# in unity 1 Answer
JSON vs XML for Unity C# 1 Answer
Handle HTML response 0 Answers
Best practice to store and load a specific set of objects? 3 Answers