Re: xml parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Lynch wrote:
I don't think that's valid XML, because you are mixing your content
with your XML tags in a way that will confuse the two...

If you can FIX the XML by using the CDATA stuff, or htmlentities
encoding the HTML or something, that would be best.

If you are STUCK with this bogus XML, you could probably write your
own parser for something this simple/small in about an hour using
http://php.net/strtok and friends...


On Sun, March 11, 2007 7:38 pm, Marije van Deventer wrote:
I have been trying to parse this xml, and want to use it with
childnodes <Label> and <Tekst>, but sofar due to the <li> and <p> and
<image> elements no luck. How can i do this in a simple way ???

<?xml version="1.0" encoding="UTF-8"?>
<Menu>
 <Item>
  <Label>Algemeen</Label>
  <Tekst>aaaaaaaaaaaaaaaaaaaaaaaaaaaaa</Tekst>
 </Item>
 <Item>
  <Label>1-Atmosfeer</Label>
  <Tekst>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  <li>aaaaaaaaaaaaaaaaaaaaa</li>
  <li>bbbbbbbbbbbbbbbbbbbbbbbbbbb</li>
  <li>ccccccccccccccc</li>
  <li>dddddddddddddddddddddddddddddddddd</li>
  <img src="Saf2.jpg" alt="News" width="240" height="232"/><br /><br
/><br />qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq<br /><br /><br
/></Tekst>
 </Item>
 <Item>
  <Label>Betrouwbare drukcabine</Label>
  <Tekst>ffffffffffffffffffffffffffffffff<img src="Saf3.jpg"
alt="News" width="180" height="239"/><br /><br /><br /><br /><br
/><br /><br /><br />gggggggggggggggggggggggggggggggggggggggggggg<br
/><br /><br /><br /><br /><br /></Tekst>
 </Item>
</Menu>

I put the above xml text into an xml editor and it tests as valid, despite its raggedness, and I did manage to get it to parse with simplexml, using the following:

$string = the above xml;

$xml = simplexml_load_string($string);

foreach($xml->Item as $item ){
  trim($item->Label);
  echo $item->Label . "<br>";
  if(isset($item->Tekst)) {
       trim($item->Tekst);
      echo $item->Tekst . "<br>";
  }
}







--

_____________________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux