Jump to content

DOMDocument member does not retain its state in class instance


dchernin

Recommended Posts

I'm trying to create a wrapper class for manipulating DOMDocument's, but it seems like my DOMDocument does not retain its state between the time I initialize it and the time I use it in subsequent function calls.  Below is a stripped down version of the class. 

 

class XMLDocument
{
private $m_XMLDocument; // DOMDocument

public function XMLDocument($xmlString)
{
	$this->m_XMLDocument = new DomDocument;
	$this->m_XMLDocument->formatOutput = true;
	$this->m_XMLDocument->preserveWhiteSpace = false;
	if (!$this->m_XMLDocument->loadXML($xmlString))
		throw new Exception("Error loading the following xml:<br />".$xmlString);
	else
	{
		print($this->m_XMLDocument->saveXML());
	}
}

public function DOMDocument()
{
	print($this->m_XMLDocument->saveXML());
	return $this->m_XMLDocument;
}

 

When I print the XML from the constructor, it works fine.  But when I call the DOMDocument function, it errors out with the following.  Anybody know how to get this working?  It's driving me nuts!

 

The XML page cannot be displayed

Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

 

 

--------------------------------------------------------------------------------

 

Only one top level element is allowed in an XML document. Error processing resource 'http://localhost/project1/Project1/ind...

 

<ThreeAces xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ThreeAces.xsd">

-^

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.