Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the information you provided with your question, it's hard to specifically say why the output gets mangled.</p> <p>So you need to step through your program and look into each point where your XML is build (already part of your question) and processed further on by your wordpress setup with it's various plugins and themes.</p> <p><strong>For that it's necessary to get an understanding where such modifications can appear.</strong></p> <p>Additionally you need a method to see the output as-is, that means <em>unchanged</em>. If you look into source-code in your browser, this often is not the case: Browsers change the output before they display it, so it's often better to dump request responses in the command-line with a HTTP client like <code>curl</code> which you can use to optionally dump the output into a file and look at with an editor <em>unchanged</em>.</p> <p>Let's recap:</p> <ol> <li>The creation of the XML must be correct firsthand.</li> <li>The XML might get changed by wordpress.</li> <li>The XML might get changed by the browser.</li> </ol> <p>This can be a lot of points to check:</p> <h3>1. The creation of the XML must be correct firsthand.</h3> <p>First of all I would look into the return value of <code>get_the_title($value['prodid'])</code> alone, so you actually know what you deal with. Probably it already contains the <code>&amp;gt;</code>? This would explain where that single <code>&amp;gt;</code> might come from. It would be valid to use it within <code>&lt;![CDATA[...]]&gt;</code> however. That's just for smelling and understanding what might happen later on.</p> <p>Next to the single value in question, you should ensure the XML itself looks correct <em>before</em> processing it furthe, which means at the end of the function. You can do so by outputting it before returning from the method and ending/exiting the application to prevent further processing:</p> <pre><code>echo "Test output:\n\n", $xml; die(); </code></pre> <p>Then look into the output. Does it looks correct? Is the problematic <code>&amp;gt;</code> already in there at the end of the cdata section in question? If yes, you know that the problem is already inside the function. If not, you know that the problem is unrelated to the function in question and that the XML is mangled later on. Depending on the outcome, you need to look for the defect.</p> <h3>2. The XML might get changed by wordpress.</h3> <p>In comments you asked:</p> <blockquote> <p>Why would var_dump be filtered? I'm running this in a plugin I'm building. Not sure why this would be filtered.</p> </blockquote> <p>Next to filtering done by the program (browser, source-viewer etc.), wordpress itself or one of it's addons (plugins, themes) might filter the output. From your comment you already say that you don't know why this can happen, therefore you don't know where this can happen as well.</p> <p>You have not shared yet how the xml is output. Are you just echo'ing it to the browser? Is it passed to some function that handles the output? This is most likely very important to find the cause of your issue. For example is your plugin answering to an XMLRPC request? In your question you're focussing a lot on the invalid XML, but you didn't share much information for which purpose the XML is being created, where it goes to and for what reason etc.. This information would be useful to understand the bigger picture.</p> <p>If you take care of the output yourself (<code>echo</code>, <code>print</code> etc.), some code might have installed an output buffer. That means your output get's buffered and probably processed later on. These output buffer related issues are harder to track down. First of all you can disable all other plugins and themes and see what happens. Wordpress itself is not making much use of output buffering (<a href="http://php.net/manual/en/book.outcontrol.php" rel="nofollow">Output Buffering Control <sup><em>[Docs]</em></sup></a>) so this could nail it quite fast because then only the default output buffering would interfere with your output.</p> <p>If you make use of a wordpress function to output the XML, then filters can be in action. Wordpress has a filter-system build in which allows itself to hook and change various data. Additionally, Wordpress core functions itself are always "trying hard" to escape output. So actually there can be a lot of points where this filtering is actually taking place. <em>"Not sure why this would be filtered."</em> - There might be no why for your case, it's just that it always happens.</p> <p>These issues can be located more easily by using an interactive debugger with breakpoints and variable inspection. It allows you to look into the program while it executes and you can see "live" what happens with the data. However you don't have it always. The other alternative is to set breakpoints yourself (<code>die</code>) and do the output yourself (<code>echo</code>, <code>var_dump</code> etc.).</p> <h3>3. The XML might get changed by the browser.</h3> <p>I've already wrote about it at the beginning and in between. Basically if you're not seeing the source as-is, but mangled by the browser, you just might suspect the cause of error wrongly. It's like using the wrong glasses and just hinders you to track things down in the first place. So know your tools.</p> <hr> <p>Things are not always easy to detect. You need to look into the right area in the first place and you need to consistently track things down. There can be various reasons why things happen if the software is more complex like Wordpress.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload