You don't want to use "xml:id" ?
Here is the relaxNG trick (with a generic schema):
(tested with libxml 2.6.26)
$doc = new DOMDocument();
$doc->load(...);
$rng = '
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<element>
<anyName/>
<ref name="anythingID"/>
</element>
</start>
<define name="anythingID">
<zeroOrMore>
<choice>
<element>
<anyName/>
<ref name="anythingID"/>
</element>
<attribute name="id">
<data type="ID"/>
</attribute>
<zeroOrMore>
<attribute><anyName/></attribute>
</zeroOrMore>
<text/>
</choice>
</zeroOrMore>
</define>
</grammar>
';
$doc->relaxNGValidateSource($rng);
var_dump($doc->getElementById('id1'));
Note that ID values must be valid ones :
- integers do no work!
- @see http://www.w3.org/TR/REC-xml/#id
- => (Letter | '_' | ':') ( Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender )*
----
Server IP: 89.31.146.176
Probable Submitter: 62.160.42.235
----
Manual Page -- http://www.php.net/manual/en/domdocument.getelementbyid.php
Edit -- https://master.php.net/note/edit/86056
Del: integrated -- https://master.php.net/note/delete/86056/integrated
Del: useless -- https://master.php.net/note/delete/86056/useless
Del: bad code -- https://master.php.net/note/delete/86056/bad+code
Del: spam -- https://master.php.net/note/delete/86056/spam
Del: non-english -- https://master.php.net/note/delete/86056/non-english
Del: in docs -- https://master.php.net/note/delete/86056/in+docs
Del: other reasons-- https://master.php.net/note/delete/86056
Reject -- https://master.php.net/note/reject/86056
Search -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.