note 106662 added to domdocument.createentityreference
| From: | sean dot cole at verizon dot net | Date: | Fri, 25 Nov 2011 14:52:11 +0000 |
| Subject: | note 106662 added to domdocument.createentityreference | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184675@lists.php.net to get a copy of this message | ||
I had some issues getting this to work, mostly because the documentation is so lacking. Here is the
help I got from stackoverflow, thanks newtover. If you're interested in the source, you can
check it out with this partial link (questions/8233394/xml-entity-in-setattribute-addattribute). I
would add the full but the requirements for submitting this suggests I don't add URL's
hopefully this is acceptable.
<?php
// a valid XML should contain used entities declarations to be valid,
// but DOM recs do not contain means to generate DTD;
// in PHP you can use XMLWriter for the purpose though
$dtd = <<<DTD
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE root [
<!ENTITY my_entity "some content">
]>
<root/>
DTD;
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->loadXML($dtd);
$root = $xml->documentElement;
$entity = $xml->createEntityReference( 'my_entity' );
$an_attr = $xml->createAttribute( 'attr' );
$an_attr->appendChild( $xml->createTextNode('prefix ') );
$an_attr->appendChild( $entity );
$an_attr->appendChild( $xml->createTextNode(' suffix') );
$root->setAttributeNode( $an_attr );
// clone the entity to use it more than once
$root->appendChild( $entity->cloneNode() );
print $xml->saveXML();
?>
----
Server IP: 69.147.83.197
Probable Submitter: 173.71.130.68
----
Manual Page -- http://www.php.net/manual/en/domdocument.createentityreference.php
Edit -- https://master.php.net/note/edit/106662
Del: integrated -- https://master.php.net/note/delete/106662/integrated
Del: useless -- https://master.php.net/note/delete/106662/useless
Del: bad code -- https://master.php.net/note/delete/106662/bad+code
Del: spam -- https://master.php.net/note/delete/106662/spam
Del: non-english -- https://master.php.net/note/delete/106662/non-english
Del: in docs -- https://master.php.net/note/delete/106662/in+docs
Del: other reasons-- https://master.php.net/note/delete/106662
Reject -- https://master.php.net/note/reject/106662
Search -- https://master.php.net/manage/user-notes.php