Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML file tobe open in notepad in correct format like xml format

Status
Not open for further replies.

harish pathak

Programmer
Oct 3, 2017
1
0
0
IN
Hi Guys,

We have a requirement to download the internal table data as XML file.

I am generating a XML file (welcome.xml) through PHP. The PHP code is as -
PHP:
<?php  
$xmlString = '<?xml version="1.0" encoding="UTF-8"?>
    <urlset 
	xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] 
	xmlns:image="[URL unfurl="true"]http://www.google.com/schemas/sitemap-image/1.1"[/URL] 
	xsi:schemaLocation="[URL unfurl="true"]http://www.sitemaps.org/schemas/sitemap/0.9[/URL] [URL unfurl="true"]http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"[/URL] 
	xmlns="[URL unfurl="true"]http://www.sitemaps.org/schemas/sitemap/0.9">[/URL]
        <url>
            <loc>[URL unfurl="true"]http://www.codexworld.com</loc>[/URL]
            <lastmod>2016-07-04T07:46:18+00:00</lastmod>
            <changefreq>always</changefreq>
            <priority>1.00</priority>
        </url>
    </urlset>';

$dom = new DOMDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->loadXML($xmlString);
$dom->formatOutput = TRUE;
//Save XML as a file
$dom->save('test/welcome.xml');

//View XML document

echo $dom->saveXml();
?>

Able to download the XML file in correct format, but when opened in NOTEPAD we are getting the complete tags of the XML in a single line.

We need the notepad file also to look like the format of the XML file when opened.

Please answer is there any solution for this (XML file should be in XML format when opened in Notepad)

Please reply as soon as possible.

Thanks in advance.

Harish Pathak
 
This is most likely more of a PHP issue, rather than an XML issue. However, you might try placing
$dom->formatOutput = TRUE;​
before you load the document. But...I also think (but certainly do not know for sure) that the loaded XML will not be pretty-printed. formatOutput (again, I think) only affects elements that are added programatically.

(I also think that you need to learn how to use the markup tools available on this site to protect characters that have special meaning in XML/HTML. I think some of your posted code doesn't make too much sense, probably because your
Code:
[code=php]
is not being recognized. Use the "Preview" button to review before submitting. Notice that the code in your post doesn't look like this...)

Tom Morrison
Consultant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top