Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
cereal_killa

Abrir xml com cdata

Recommended Posts

cereal_killa

Boas,

Estou com um problema em ler um ficheiro xml com conteudo cdata, ja tentei de varias maneiras e até agora nada.

O codigo do xml é o seguinte :

<?xml version="1.0" encoding="iso-8859-1"?>
<root>
<item>
  <title><![CDATA[<font size='22' color='#338FF3'>Ferro Wink</font><br><font size='14' color='#ffffff'>lfsdjbnvsjdfxcngofsjdgnodf</font>]]></title>
  <content><![CDATA[ <img src='imgs/mats/43.jpg' vspace='-15' hspace='-2' height='235' width='550' > ]]></content>
</item>
<item>
<title><![CDATA[<font size='22' color='#338FF3'>Aço</font><br><font size='14' color='#ffffff'>lfsdjbnvsjdfxcnodfjgndofgn</font>]]></title>
  <content><![CDATA[ <img src='imgs/mats/1.jpg' vspace='-15' hspace='-2' height='235' width='550' > ]]></content>
</item>
<item>
<title><![CDATA[<font size='22' color='#338FF3'>Madeira</font><br><font size='14' color='#ffffff'>lfssjdvsjdfxcnnodfjgndofgn</font>]]></title>
  <content><![CDATA[ <img src='imgs/mats/3.jpg' vspace='-15' hspace='-2' height='235' width='550' > ]]></content>
</item>
<item>
<title><![CDATA[<font size='22' color='#338FF3'>Materiais</font><br><font size='14' color='#ffffff'>ljsdjofsjdgnodfjgndofgn</font>]]></title>
  <content><![CDATA[ <img src='imgs/mats/4.jpg' vspace='-15' hspace='-2' height='235' width='550' > ]]></content>
</item>
<item>
<title><![CDATA[<font size='22' color='#338FF3'>Procura</font><br><font size='14' color='#ffffff'>yb5yuyr65xcnggofdfjgndofgn</font>]]></title>
  <content><![CDATA[ <img src='imgs/mats/1.jpg' vspace='-15' hspace='-2' height='235' width='550' >]]></content>
</item>
</root>

O codigo do meu php neste momento :

<?php

class SimpleXMLExtended extends SimpleXMLElement

{

  public function addCData($cdata_text)

  {

    $node= dom_import_simplexml($this);

    $no = $node->ownerDocument;

    $node->appendChild($no->createCDATASection($cdata_text));

  }

}

$xml = new SimpleXMLExtended('../xml/mats.xml');

$mynode = $xml->addChild("myname");

$mynode->addCData("my name contains everything I want &%<>");

$xml->asXml('../xml/mats1.xml');

?>

E o erro que me da :/

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' not found in C:\Programas\wamp\www\php\addmat.php on line 13

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ../xml/mats.xml in C:\Programas\wamp\www\php\addmat.php on line 13

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in C:\Programas\wamp\www\php\addmat.php on line 13

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\Programas\wamp\www\php\addmat.php:13 Stack trace: #0 C:\Programas\wamp\www\php\addmat.php(13): SimpleXMLElement->__construct('../xml/mats.xml') #1 {main} thrown in C:\Programas\wamp\www\php\addmat.php on line 13

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.