|
Posted by Benjamin on 08/06/07 16:06
On Aug 6, 9:44 am, php.developer2...@gmail.com wrote:
> Hi i want to parse a xml document which contains attribute can anybody
> help me in that.
>
> Example
> --------------------
> <category id="1" parent-id="1" level="2">
> <category id="2" parent-id="1" level="3">
> <category id="3" parent-id="5" level="6">
>
> I want to get all id's in this example with using regular
> expressions..
>
> Output
> ----------
> 1
> 2
> 3
First of all that's not valid XML. In order to parse it, it has to be
valid. This, however, is easily fixed in your case. Just put the whole
body in <categories> tags and add the XML declaration like this:
<?xml version="1.0"?>
<categories>
<category id="1" parent-id="1" level="2">
<category id="2" parent-id="1" level="3">
<category id="3" parent-id="5" level="6">
</categories>
With PHP, you have many options to parse XML with. My favorite and
probably the most easy is SimpleXML. Look at http://www.php.net/simplexml.
Navigation:
[Reply to this message]
|