Jump to content
xisto Community
demolaynyc

DOMXML In PHP

Recommended Posts

So I started taking a tutorial on PHP DOMXML which is said to be part of the PHP Core. However, when I tried it out in Xisto server (I used the exact script and file so I know it should work) It didn't work...Is DOM XML part of the PHP Core of Xisto because I see it in the phpinfo().Must I enable something in the php.ini file?

Share this post


Link to post
Share on other sites

So I started taking a tutorial on PHP DOMXML which is said to be part of the PHP Core. However, when I tried it out in Xisto server (I used the exact script and file so I know it should work) It didn't work...
Is DOM XML part of the PHP Core of Xisto because I see it in the phpinfo().

Must I enable something in the php.ini file?

Yes it is part of the PHP Core as you see it in the phpinfo() result page, also you dont need to enable anything in the php.ini file.

Now, this extension should no longer be used instead the official php site recommends to use the DOM extension, that is the replacement for the DOM XML extension from PHP 4.

Best regards,

Share this post


Link to post
Share on other sites

Ok, here's the code I tried:

<?php# make an example xml document to play with$xmlstr = "<" . "?" . "xml version=\"1.0\"" . "?" . ">";$xmlstr .="<employee>	<name>Matt</name>	<position type=\"contract\">Web Guy</position></employee>";# load xml data ($doc becomes an instance of # the DomDocument object)$doc = xmldoc($xmlstr);# get root node "employee"$employee = $doc->root();# get employee's children ("name","position")$nodes = $employee->children();# let's play with the "position" node# so we must iterate through employee's# children in search of itwhile ($node = array_shift($nodes)){	if ($node->name == "position")	{		$position = $node;		break;	}}# get position's type attribute$type = $position->getattr("type");# get the text enclosed by the position tag# shift the first element off of position's children$text_node = array_shift($position->children());# access the content property of the text node$text = $text_node->content;# echo out the position and typeecho "position: $text<BR>";echo "type: $type";?>


And this is the output I get when I load it:

Warning: domdocument() expects at least 1 parameter, 0 given in /home/demnyc/public_html/dom.php on line 2
Fatal error: Call to undefined function: load() in /home/demnyc/public_html/dom.php on line 3


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.