eaglehopes Posted June 18, 2022 Share Posted June 18, 2022 (edited) I have a home.html page in where I put some example XML code ( I got this code from https://www.sitemaps.org/protocol.html) : <pre><code> <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> ..... </url> <url> ..... </url> <url> ..... </url> <url> ..... </url> . . . </urlset> </code></pre> I am using PHP to include my home.html page into the main page(i.e. index.php) : ... <div><?php include "./p/home.html" ?> </div> ... In final, XML code gives error because it contains "<?" and "?>". How I used "<pre><code>....</code></pre>" and put above XML code inside it, but no success. How can I correctly show my code part in my home.html page? Thanks Edited June 18, 2022 by eaglehopes I add where I got XML code and change title too. Quote Link to comment https://forums.phpfreaks.com/topic/314938-how-to-treat-an-xml-code-in-html-page-correctly/ Share on other sites More sharing options...
Solution Barand Posted June 18, 2022 Solution Share Posted June 18, 2022 Perhaps echo '<pre>' . htmlentities(' <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> ..... </url> <url> ..... </url> <url> ..... </url> <url> ..... </url> </urlset> ') . '</pre>'; 1 Quote Link to comment https://forums.phpfreaks.com/topic/314938-how-to-treat-an-xml-code-in-html-page-correctly/#findComment-1597435 Share on other sites More sharing options...
eaglehopes Posted June 18, 2022 Author Share Posted June 18, 2022 2 hours ago, Barand said: Perhaps echo '<pre>' . htmlentities(' <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> ..... </url> <url> ..... </url> <url> ..... </url> <url> ..... </url> </urlset> ') . '</pre>'; I used your code in my webpage and worked like a charm. Thanks, I did not know .htmlentities function of PHP. Quote Link to comment https://forums.phpfreaks.com/topic/314938-how-to-treat-an-xml-code-in-html-page-correctly/#findComment-1597436 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.