note 86056 modified in domdocument.getelementbyid by danbrown

From: Date: Wed, 01 Oct 2008 16:32:23 +0000
Subject: note 86056 modified in domdocument.getelementbyid by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-144943@lists.php.net to get a copy of this message
You don't want to use "xml:id" ? Here is the relaxNG trick (with a generic schema): (tested with libxml 2.6.26) <?php $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 )* --was-- 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 )* http://php.net/manual/en/domdocument.getelementbyid.php

« previous php.notes (#144943) next »