Jump to content

How to treat an XML code in html page correctly?


Go to solution Solved by Barand,

Recommended Posts

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 by eaglehopes
I add where I got XML code and change title too.
  • eaglehopes changed the title to How to treat an XML code in html page correctly?
  • Solution

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>';

 

  • Thanks 1
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. :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.