Forum OpenACS Q&A: Re: what is the best practive for extracting xml like info from variables

The only reason I would see to use XML is if you need to store multiple addresses per 'record', in a nested format, or if you are gonna further pass that data outside to some other machine that wants XML data.

Here's what I mean:

<contact>

<home>
<address>
<street>1 Main St</street>
<city>Plainville</city>
<state>New York (or NY)</state>
</address>
<phone>
<number>123-4567</number>
<type>mobile</type>
</phone>
</home>

<work>
<address>
<street>1 Main St</street>
<city>Plainville</city>
<state>New York (or NY)</state>
</address>
<phone>
<number>123-4567</number>
<type>mobile</type>
</phone>
</work>

</contact>

I'm ignoring that tags don't need to balance in XML, (e.g. <number/>123-4567 could be valid )..

If it's nesting, the regex won't help with balanced tags or not, because you'll have two that match <street>xxx</street> or <street/> .. You really need to parse the tree, which is what ns_xml and similar tools are designed to do.