List Info

Thread: note 71472 added to function.xml-parse-into-struct




note 71472 added to function.xml-parse-into-struct
user name
2006-11-30 12:48:05
That parser also has a problem in which it will not parse
more items than the current level it is on. That is, parsing
this: 
<1><2>A</2><2>B</2><2>C&
lt;/2></1>
Will only result in this: A B
C is never processed.

It might be better with something like this:
          $file = get_url('http://news.search.yahoo.com/news/rss?p=current+events
', URL_CONTENT);
          $data = $file['content'];
          $xml_parser = xml_parser_create();
          xml_parse_into_struct($xml_parser, $data, $vals,
$index);
          xml_parser_free($xml_parser);
          //Uncomment the lines below to see the entire
structure of your XML document
          //echo "<pre>INDEX: n";
          //print_r ($index);
          //echo "n n n VALUES:";
          //print_r ($vals);
          //echo "</pre>";
          $params = array();
          $level = array();
          $start_level = 1;
          foreach ($vals as $xml_elem) {
            if ($xml_elem['type'] == 'open') {
              if (array_key_exists('attributes',$xml_elem))
{
                list($level[$xml_elem['level']],$extra) =
array_values($xml_elem['attributes']);
              } else {
                $level[$xml_elem['level']] =
$xml_elem['tag'];
              }
            }
            if ($xml_elem['type'] == 'complete') {
              $php_stmt = '$params';
              while($start_level < $xml_elem['level']) {
                $php_stmt .= '[$level['.$start_level.']]';
                $start_level++;
              }
              $php_stmt .= '[$xml_elem['tag']][] =
$xml_elem['value'];';
              eval($php_stmt);
              $start_level--;
            }
          }
          echo "<pre>";
          print_r ($params);
          echo "</pre>";

~Tim_Myth
----
Server IP: 216.194.113.175
Probable Submitter: 144.226.230.37 (proxied: 10.240.16.21)
----
Manual Page -- http://www.php.net/manual/en/function.xml-parse-i
nto-struct.php
Edit        -- https://master
.php.net/note/edit/71472
Del: integrated  -- h
ttps://master.php.net/note/delete/71472/integrated
Del: useless     -- http
s://master.php.net/note/delete/71472/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/71472/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/71472/spam
Del: non-english -- 
https://master.php.net/note/delete/71472/non-english
Del: in docs     -- http
s://master.php.net/note/delete/71472/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/71472
Reject      -- https://mast
er.php.net/note/reject/71472
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )