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 6639591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:34:17+00:00 2026-05-25T23:34:17+00:00

I have: $XML = new DOMDocument(); $XML->load(‘demo.xml’); $xpath = new DOMXpath($XML); $elements = $xpath->evaluate($_GET[xpath]);

  • 0

I have:

$XML = new DOMDocument();
$XML->load('demo.xml');

$xpath = new DOMXpath($XML);
$elements = $xpath->evaluate($_GET["xpath"]);

$XSL = new DOMDocument();
$XSL->load('xml2json.xsl', LIBXML_NOCDATA);

$xslt = new XSLTProcessor();
$xslt->importStylesheet($XSL);

echo $xslt->transformToXML($elements);

I get the following error:

( ! ) Warning: XSLTProcessor::transformToXml() [xsltprocessor.transformtoxml]: Invalid Document in C:\wamp\www\content.php on line 18

How do I convert a DOMNodeList to a DOMDocument to make this work?

Here is how I got it to work!

function getContent(&$NodeContent="",$nod)
{    $NodList=$nod->childNodes;
    for( $j=0 ;  $j < $NodList->length; $j++ )
    {       $nod2=$NodList->item($j);//Node j
        $nodemane=$nod2->nodeName;
        $nodevalue=$nod2->nodeValue;
        if($nod2->nodeType == XML_TEXT_NODE)
            $NodeContent .=  $nodevalue;
        else
        {     $NodeContent .= "<$nodemane";
           $attAre=$nod2->attributes;
           foreach ($attAre as $value)
              $NodeContent .=" {$value->nodeName}='{$value->nodeValue}'" ;
            $NodeContent .=">";                    
            getContent($NodeContent,$nod2);                    
            $NodeContent .= "</$nodemane>";
        }
    }

}


$XML = new DOMDocument();
$XML->load('demo.xml');

$xpath = new DOMXpath($XML);
$elements = $xpath->query($_GET["xpath"]);

$XSL = new DOMDocument();
$XSL->load('xml2json.xsl', LIBXML_NOCDATA);

$xslt = new XSLTProcessor();
$xslt->importStylesheet($XSL);

$newdoc = new DOMDocument;
$newdoc -> preserveWhiteSpace = false;
$newdoc -> formatOutput = true; 

$elm = $elements->item(0);
getContent($docstring,$elm);
$docstring = '<root>'.$docstring.'</root>';
$docstring = str_replace(array("\r\n", "\r", "\n", "\t"), '', $docstring);
$newdoc -> LoadXML($docstring);
echo $xslt->transformToXML($newdoc);
  • 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-25T23:34:17+00:00Added an answer on May 25, 2026 at 11:34 pm

    You are doing

    $elements = $xpath->evaluate($_GET["xpath"]);
    …
    echo $xslt->transformToXML($elements);
    

    The return values for DOMXPath::evaluate() are

    Returns a typed result if possible or a DOMNodeList containing all nodes matching the given XPath expression. If the expression is malformed or the contextnode is invalid, DOMXPath::evaluate() returns FALSE.

    The method signature for transformToXML() states

    string XSLTProcessor::transformToXML ( DOMDocument $doc )
    

    In other words, you are not passing a DOMDocument and get an “Invalid Document” error.

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

Sidebar

Related Questions

i have a problem to load a xml-file with php. I use DOMDocument, because
I have an XML document: var xml:XML = new XML(<rootNode> <head> <meta name=template content=Default
I am new to MVC and facing one issue. I have a xml file
I have a single xml file and every new thread of the program (BHO)
still new to XML parsing with the iphone so i have a few questions.
If I have the following xml: XDocument xDocument = new XDocument( new XElement(RootElement, new
I have the following XML document: <projects> <project> <name>Shockwave</name> <language>Ruby</language> <owner>Brian May</owner> <state>New</state> <startDate>31/10/2008
I'm new to AS3 and have been working on an XML driven navigation system
I have this code: ... request data = new request(); data.username = formNick; xml
Greetings, I'm new to TCL scripting, and I have a very very basic xml

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.