How include and read HTML for a XML?
<myxml>
<bla>
I want <strong>HTML here</strong>
</bla&g开发者_JAVA技巧t;
</myxml>
How can I read the HTML from the XML document?
$data = file_get_contents('myxml.xml');
$xml = new SimpleXMLElement($data);
print_r($xml); // fail...
ps: without escaping, because it's annoying to escape the text each time I add something..
edit:
<myxml>
<bla><![CDATA[I want <strong>HTML here</strong>]]></bla>
</myxml>
the PHP:
$xml = simplexml_load_file('myxml.xml');
print_r($xml);
and the output is:
SimpleXMLElement Object
(
[bla] => SimpleXMLElement Object
(
)
)
no cdata there..
Surround your I want <strong>HTML here</strong> with CDATA tags, as such:
<![CDATA[
I want <strong>HTML here</strong>
]]>
This will tell parsers to ignore what's inside the CDATA block and just parse it as plaintext.
Explicit typecast is not required for text nodes, and it works only there; print_r() is the wrong function/language feature to use here (use echo instead).
For printing the content of any SimpleXML element as XML (one that may also contain other elements), use its asXML() method.
加载中,请稍侯......
精彩评论