Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6937199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:19:57+00:00 2026-05-27T12:19:57+00:00

I am building a website in PHP in which the content is stored in

  • 0

I am building a website in PHP in which the content is stored in an XML file. Basically I have a single index.php page, which checks the querystring and serves the appropriate page from the XML.

For example, entering www.mysite.com/?page=home would cause the PHP script to check the XML file for a <page id="home"> tag and paste whatever is inside that tag into index.php.

The contents of <page> tags are stored as HTML, thus:

<xmlroot>
  <page id="home">
    <h1>An HTML Header Tag!</h1>
    <p>This is a paragraph</p>
  </page>
  [...etc]
</xmlroot>

I was hoping to be able to grab the appropriate <page> tag and somehow parse the contents. I know that everything in the <page> tag is valid HTML, so I was just going to use expat to run through the tags and echo them straight back out.

So I am using the DOMDocument method to find the correct <page>, which works fine, except that the contents are returned as a DOM element. The expat parser requires a string. So I need to do one of two things:

  1. Magically convert the DOM element to a string that keeps all the tags intact so I can use it in the expat parser. However, if I could do this I wouldn’t need the expat parser, I could just echo that converted string straight out….

  2. Use something other than expat.

Incidentally, I know I could just replace the < and > in the XML with &lt; and &gt;, but this makes the code quite hard to read and edit. I’d like to avoid it if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:19:58+00:00Added an answer on May 27, 2026 at 12:19 pm
    <?php
    
    $doc = new DOMDocument('1.0');
    
    $root = $doc->createElement('html');
    $root = $doc->appendChild($root);
    
    $head = $doc->createElement('head');
    $head = $root->appendChild($head);
    
    $title = $doc->createElement('title');
    $title = $head->appendChild($title);
    
    $text = $doc->createTextNode('< This is the title >');
    $text = $title->appendChild($text);
    
    echo $head->ownerDocument->saveXML($head);
    

    DOMDocument::saveXML() takes $node parameter to output only a specific node


    http://www.php.net/manual/en/domdocument.savexml.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a website in PHP which contains flash in its index page. I
I am building a website using php+mysql. I have a registration page and its
I'm building the basic framework for my website and I have a config.php file
I have been using PHP and JavaScript for building my dad's website. He wants
I am building a website in which the main content frame should span the
I'm building a website that will be an open-source, user-contributed content kind of thing,
I'm building my own website in PHP, somehow my tracking has stopped working since
I am building a login page for my website. Right now it is very
I am building a networking website which allows users to upload images. When one
I am building a website in PHP & mySQL. It has frontend and backend

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.