How to undo an XML string on an HTML page for debugging?

So, I have a php script, and I need to somehow view the value of one of my variables. The fact is that this variable is a very long XML string received from the server. I know there is an error message in it, but I need to see what it says. If I try to print or change the value, it displays only the part that follows ... or if I use var_dump, it does the same. I even went as far as trying to repeat a javascript warning with a value, but it fails because the xml has single and double quotes, as a result of which the quotes of the warnings are not recognized correctly. I just need to see the value of this variable. Any advice? Thanks.

Edit: Actually, this is wrong. Echo and print do not display the value correctly because the tags are in <> brackets, therefore it is recognized as an html tag.

+7
source share
6 answers

You can use htmlentities to output the XML string so that you can view it as a browser in clear text.

<?php echo htmlentities( $xml_string); ?> 

Alternatively, you can parse an XML string to display an error message, but it can be more complex than what you need.

+13
source

Try echo htmlentities($var, ENT_COMPAT, 'UTF-8')

+5
source

Try the following:

 echo '<pre>'.$xml_string.'</pre>'; 

See also: CDATA Character Data - (Unparsed)

+3
source

i always use this:

 echo "<pre>". htmlentities($s) . "</pre>"; 
+2
source

i usaly use:

 echo nl2br(str_replace('<', '&lt;', $xml)); 

since its only <is the problem

+1
source

You can simply save the XML string to a file. If it's well-formed XML, you can view it with every browser (and expand / collapse ^^ nodes).

0
source

All Articles