0

I essentially have an xml file in which one attribute is a link which has &'s. I'm unable to parse this with simplexml_load_string so I'm using htmlspecialchars on it before xml parse and htmlspecialchars_decode after xml parse. But this is not working. the xml parse keeps failing. My code is as follows.

public static function parseXMLStr($xml_str) {
            $xml_str=htmlspecialchars($xml_str, ENT_NOQUOTES);
            self::$xml=simplexml_load_string($feature_ban_xml_str);
            if(isset(self::$xml->link)) {

               .....

What is going wrong? Am i understanding something incorrectly?

edit: xml

<?xml version="1.0" encoding="UTF-8"?>
<link>
   <sublink active="true" redirect="http://abc.def.com/abcdef?id=&cId=45&kId=kA16000">
   </sublink>
</link>

I have to add, str_replace('&','&amp;','') and back works well. But I need something robust and not just for &'s

Aks
  • 5,188
  • 12
  • 60
  • 101
  • Can you post the relevant sections of the XML? – nickb Jul 06 '12 at 13:39
  • Check out http://stackoverflow.com/questions/1289524/is-it-possible-to-have-html-text-or-cdata-inside-an-xml-attribute. Basically you need to apply `htmlspecialchars` for your redirect attribute alone. btw htmlspecialchars perfectly replaces & to `&` – Tamil Jul 06 '12 at 14:41

1 Answers1

0

If you want to just to encode the link of the attribute, the you can use url_encode, url_decode

satdev86
  • 800
  • 7
  • 14