Page 1 of 1

xml parser question

Posted: Fri Jan 08, 2010 4:29 pm
by dcinadr
i am trying to get a data structure from and xml string using the xml_parse_into_struct() function. My problem is that its adding only the first tag of my xml string.

my xml string looks like this:

Code: Select all

 
<?xml version="1.0" encoding=UTF-8"?>
<UserLog>
    <rec num="18" type="1">This is line 18</rec>
    <rec num="19" type="1">This is line 19</rec>
</UserLog>
 
But the output looks like this:

Code: Select all

 
Array
(
    [0] => Array
        (
            [tag] => USERLOG
            [type] => open
            [level] => 1
            [value] => 
        )
)
 
I was expecting the output to look something more like this:

Code: Select all

 
Array
(
    [0] => Array
        (
            [tag] => USERLOG
            [type] => open
            [level] => 1
        )
    [1] => Array
        (
            [tag] => REC
            [type] => complete
            [level] => 2
            [attributes] => Array
                (
                    [ID] => 18
                    [TYPE => 1
                )
            [value] => This is line 18
        )
    [2] => Array
        (
            [tag] => REC
            [type] => complete
            [level] => 2
            [attributes] => Array
                (
                    [ID] => 19
                    [TYPE => 1
                )
            [value] => This is line 19
        )
 
)
 
what am i doing wrong?

Thanks.

Re: xml parser question

Posted: Fri Jan 08, 2010 4:33 pm
by dcinadr
oops forgot to post my code...

Code: Select all

 
<?php
ob_start();
passthru("$executable");
$rawXml = ob_get_contents();
ob_end_clean();
$xmlParser = xml_parser_create();
xml_parser_ser_option($xmlParser, XML_OPTION_TARGET_ENCODING, "UTF-8");
xml_parse_into_struct($xmlParser, $rawXml, $vals, $index);
print_r($vals);
?>
 

Re: xml parser question

Posted: Fri Jan 08, 2010 5:57 pm
by dcinadr
well i figured out my problem. There was a syntax problem with the xml output...

<rec num="18" type=1">

was missing a quote. should have been...

<rec num="18" type="1">