[SOLVED] List XML elements

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
Ragnis
Forum Commoner
Posts: 31
Joined: Thu Nov 13, 2008 12:35 pm
Location: Saaremaa, Estonia, Europe, Asia, Planet Earth, The Solar System, Milky way.

[SOLVED] List XML elements

Post by Ragnis »

I have the following XML:

Code: Select all

<root>
    <set key="sth" />
    <uname>Somebody</uname>
    <container>
        <uname>Somebody</uname>
        <container>
            Some content
        </container>
    </container>
    Some text
</root>
Now i need a regex to get list of the elements:

Code: Select all

root,set,uname,container
or it can be also an array.
Last edited by Ragnis on Sat Jan 23, 2010 11:42 am, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: List XML elements

Post by Christopher »

Have you tried SimpleXML first?
(#10850)
User avatar
Ragnis
Forum Commoner
Posts: 31
Joined: Thu Nov 13, 2008 12:35 pm
Location: Saaremaa, Estonia, Europe, Asia, Planet Earth, The Solar System, Milky way.

Re: List XML elements

Post by Ragnis »

I got it working myself.

Code: Select all

<([a-z:]+)(.+)?( /)?>
Post Reply