Reputation: 113
I would need to parse an XML file which contains a CDATA tag. Inside this tag, there is another tag that I want to get. How can I achieve this by using XMLReader?
Example:
<glz:Param name="TITLE">
<![CDATA[Yellow <http://www.yellow.it>]]>
</glz:Param>
How can I get the whole info Yellow <http://www.yellow.it>
? I can only get 'Yellow'.
This is my code:
// load file, create a reader variable, etc.
if($reader->nodeType == XMLReader::CDATA)
{
echo $reader->value;
}
Upvotes: 0
Views: 840
Reputation: 316969
As per your comments:
The issue is likely that XmlReader correctly fetches the entire content in the CDATA tag, but your browser inteprets it as html again. Check the page source to see if it contains the a element. If so, try
echo htmlentities($reader->value);
or send a header with content-type: text/plain.
Upvotes: 1
Reputation: 60
You can get it by string search. As you can see, String "http://www.yellow.it]]>"is not XML so that you can not parse it using XMLReader. Please search string on it. For example, you can split the string as "http:" and you can get 2 sub strings. From second String, you can get the full link without ">]]>".
Hope it will be helpful.
Upvotes: 0