Regex ordering

vladrac

Newcomer
Joined
Feb 16, 2004
Messages
2
Any idea how I can capture both id and name from the xml below


<person>
<id>3</id>
<name>gareth</name>
</person>
<person>
<name>fred</name>
<id>4</id>
</person>


I have tried to do this

<id>(?<the_id>[^<]*)</id>.+?<name>(?<the_name>[^<]*)</name>

Notice the ordering of the second persons nodes

I don't want to specify all the ordering options like this (see below) as this gets out of control for large numbers of combinations

<id>(?<the_id>[^<]*)</id>.+?<name>(?<the_name>[^<]*)</name>|<name>(?<the_name>[^<]*)</name>.+?<id>(?<the_id>[^<]*)</id>

Any help would be appreciated
 
I suggest just doing two matches - one to get the ID, then one to get the name.

However, is there a reason you're not using tools in the System.XML namespace for parsing through this?

It would seem to make things a whole thing a lot easier than messing around with regex objects.
 
I have been tasked with decomposing XML that is stored in a DB, it is currently decomposed using XML classes but it just isn't quick enough,

We are processing millions of megs of XML an hour,

So regex seems to be the best choice,

Currently it looks like the only solution is to match chunks of XML then use seperate expression for each match
 
Back
Top