If you can help with this you're a genius.
Basically, I will have some text like this:
<parent wealthy>
<parent>
<children female>
<child>
jessica
<hobbies>
basketball, soccer, video games
</hobbies>
</child>
<child>
jane
<hobbies>
cooking, shopping, boys
</hobbies>
</child>
</children female>
<children male>
<child>
josh
<hobbies>
tennis, swimming
</hobbies>
</child>
</children male>
</parent>
</parent wealthy>
<parent poor>
<parent>
<children male>
<child>
---
<hobbies>...</hobbies>
</child>
</children male>
</parent>
</parent poor>
So in all, I will have a parent-child hierarchy like this:
- parent wealthy/ parent poor /parent something else
-- parent
-- children male/ children female / children something else
-- child
-- (name of the child is given without any tags around it)
-- hobbies
I'm wondering how I can possibly parse all this info out and have them stored in a php array/object/variable while maintaining the order in which they appear? For example, if <parent wealthy>
appears above <parent poor>
I would like to keep them in the same order, and the same thing goes if <children male>
appear before <children female>
.
This would be almost perfectly valid XML and I could use SimpleXML to parse it, however the problem is that the name of the child doesn't appear between any tags and the client wants to keep it this way for user friendliness. for example:
<child>
jane
<hobbies>
cooking, shopping, boys
</hobbies>
</child>
Here 'jane' appears outside any tags, and the <hobbies>
appear between some tags.
How can this be parsed? Please give some advice. If you suggest using regexps, please give the regexps that can be used for your answer to be accepted, as I don't know regexps.
Thanks.
Edit: The main problem is that the client wants to mix normal text with text in tags. For example:
text text test <hobbies>...<hobbies>. text text text <age>30</age>
How can that be parsed?