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

  • Home
  • SEARCH
  • 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 3395264
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:16:09+00:00 2026-05-18T04:16:09+00:00

I am completely new to DOM Documents, basically what I am trying to do,

  • 0

I am completely new to DOM Documents, basically what I am trying to do, is to load a RSS feed in and select only one node, and then save it to a XML file.

Here is the XML I am loading from a web feed:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
    <channel>
        <title>Markets</title>
        <description/>
        <link>http://www.website.com</link>
        <language>en-us</language>
        <copyright>XML Output Copyright</copyright>
        <ttl>15</ttl>
        <pubDate>Tue, 16 Nov 2010 09:38:00 +0000</pubDate>
        <webMaster>admin@website.com</webMaster>
        <image>
            <title>title</title>
            <url>http://www.website.com/images/xmllogo.gif</url>
            <link>http://www.website.com</link>
            <width>144</width>
            <height>16</height>
        </image>


            <item>
                <title>title</title>
                <description>the description goes here
                </description>
                <enclosure url="http://www.website.com/images/image.png" type="image/png"/>

            </item>

    </channel>
</rss>

Here is my lame attempt at getting the <description> node and saving it to feed.xml:

<?php  

    $feed = new DOMDocument();
    $feed->load('http://www.website.com/directory/directory/cz.c');
    $nodeValue = $feed->getElementsByTagName('description')->item(0)->nodeValue;
    $feed->save("feed.xml");

?>

So basically I need to get the description tag, and save it as a XML file.

Any help would be appreciated, thanx in advance!

  • 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-18T04:16:09+00:00Added an answer on May 18, 2026 at 4:16 am

    Almost correct. To get the “outerXml” of a node, you can pass the node to saveXml()

    $feed = new DOMDocument();
    $feed->load('http://www.website.com/directory/directory/cz.c');
    $xml = $feed->saveXml($feed->getElementsByTagName('description')->item(0));
    file_put_contents("feed.xml", $xml);
    

    Saving with file_put_contents will not include an XML prolog. Note that in your example, the first description element is empty, so the file will contain <description/>.

    If you want to extract the node as standalone XML Document, you have to instantiate a new DOMDocument and import the DOMNode and then use save().

    $dom = new DOMDocument($feed->xmlVersion, $feed->xmlEncoding);
    $dom->appendChild(
        $dom->importNode(
            $feed->getElementsByTagName('description')->item(0),
            TRUE
        )
    );
    echo $dom->save('new.xml');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completely new to AIR but what I'm trying to do feels like it
Completely new to asp.net mvc... completely new to web apps so bear with me...
Completely new to java and I have been playing around with regex in a
I am completely new in Windowsphone7.i have develop sample application in that i want
I'm building a completely new version of my website (currently runs on phpBB and
I am completely new to ruby and I inherited a ruby system for a
I am completely new to LINQ in C#/.NET. I understand that I could use
I'm completely new at C# and NUnit. In Boost.Test there is a family of
I'm completely new to Flex and am just having a play with a sample
I'm completely new to LaTeX and something I'm wanting to do is eluding me.

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.