-1

EDIT: HOW IS THIS TOO BROAD? My question was put on hold for being too broad, but I asked one question and provided screenshots and sourcecode. What more do I need? I feel this was flagged for closure before the people that flagged it read everything here. I provided the full source code of my file. HELP! I don't feel very welcome. :-(

I followed the answer in this question to take an existing XML feed, change some tag names, and then spit out a new feed:

How do I change XML tag names with PHP?

The issue I am having is that when the feed is displayed in any browser, it displays as text, instead of being nicely formatted like other 'normal' XML feeds. I assume that since I have not told PHP to render the page as XML, it assumes text/html by default, and that is why it is happening. HOWEVER, when I specify in the header that it's XML, it generates with some XML formatting, but all of my feed shows up bold between the 'pre' tags that are in that answer linked above. When removing the 'pre' tag from the source, it generates nothing.

Without Header Specifying XML:

Rendering as Text

With Header Specifying XML:

Rendering Improperly as XML

Does anyone have any hints to guide me to get this to render properly in a browser?

Thanks in Advance!

Source linked in comments below. StackOverflow would not let me add a third link.

Community
  • 1
  • 1
TechSalad
  • 1
  • 2
  • 1
    Show more of your code implementation please. – Scuzzy Mar 28 '17 at 21:21
  • 1
    You certainly shouldn't be outputting `
    ` tags. Excluding them should give you the exact same XML outputted directly to the DOM. I think the answerer in the linked question was just showcasing the output of the XML. Try using `print_r(htmlspecialchars($xml));` directly.
    – Obsidian Age Mar 28 '17 at 21:22
  • @ObsidianAge When I do that without specifying XML in the headers, it displays as text. When I add XML to the header, it displays a blank page. header("Content-type: text/xml"); – TechSalad Mar 28 '17 at 21:37
  • Source: https://ufile.io/4fee1 – TechSalad Mar 28 '17 at 21:40
  • This question fits the rules. Can someone review it to take it off hold? Or at least provide an explanation? Would love to be welcomed into the community, rather than shunned right out the gate. If I need to do something different, just say so....please and thank you. – TechSalad Mar 30 '17 at 19:22
  • @TechSalad it's been closed as Too Broad because you haven't provided a [mcve] that illustrates your problem with a specific question. Instead you just linked to a couple of random screenshots and a sketchy external site with your full code file. Edit your question to include only the pertinent information and a more specific question about what you're trying to achieve and what's stopping you getting there. – Steve Mar 31 '17 at 01:45
  • I disagree. I provided clear-cut explanation of what I see and what I am looking to achieve. Because my source contains pre-tags, I could not use pre-tags to post the source within my post without causing havoc. What is an approved site to link to with source code? Instead of bullying us new users and force-closing our questions, how about offering advice as to how we can better be helped? – TechSalad Apr 06 '17 at 21:07

2 Answers2

0

Fixed it!

I replaced:

    `echo 'PRETAG'; print_r(htmlspecialchars($xml)); echo 'PRETAG';`

with

    `print_r($xml);`

And added the XML content type to the header:

    `header ("Content-Type:text/xml");`

My original source (as posted in the comments above), is available here: Source: ufile.io/4fee1

TechSalad
  • 1
  • 2
-1

Have you run the resulting code through an xml validator to make sure your rename function is returning valid xml syntax?

If your only problem is having it render in a browser you might look into simple_xml_load_string or SimpleXMLElement to parse your xml into workable objects.

simplexml_load_string
$showme = simplexml_load_string($xml);
print_r($showme);

SimpleXMLElement

$showme = new SimpleXMLElement($xml);
echo $showme->asXML();
Neil
  • 14,063
  • 3
  • 30
  • 51
Dano
  • 169
  • 9
  • Welcome to StackOverflow! While answers are always appreciated, unfortunately, this is not an answer to a question. An answer directly solves the problem at hand, rather than asks for additional information. When you get enough [**reputation**](http://stackoverflow.com/help/whats-reputation), you'll be able to [**add comments to questions**](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). Until then, try to only answer questions that don't require clarification :) – Obsidian Age Mar 28 '17 at 21:52
  • To answer your question, yes, I did run the resulting XML through an XML validator, and there were no errors. – TechSalad Mar 28 '17 at 22:03