# dom_document_get_element_by_id

- Thread: https://externals.io/message/4427
- Original archive: https://news-web.php.net/php.internals/4427
- Started by John Huntjens on 2003-09-08T15:11:19+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #4427 — John Huntjens — 2003-09-08T15:11:19+00:00

URL: https://externals.io/message/4427#4427

Is this function working?

Test program:

$dom = new domDocument();
$dom->load("test.xml");
$node = $dom->getElementById("id1");
print_r($node);

Test file:

<?xml version="1.0" encoding="utf-8"?>
<test>
 <el1 id="id1"/>
 <el2 id="id2"/>
</test>

It seems to me that always a emty object is returned?

---

## #4428 — Christian Stocker — 2003-09-08T15:17:25+00:00

URL: https://externals.io/message/4427#4428 · In reply to: #4427

> Is this function working?
yes.

see:

http://bugs.php.net/bug.php?id=17629
http://bugs.php.net/bug.php?id=16647

for details

chregu

> 
> Test program:
> 
> $dom = new domDocument();
> $dom->load("test.xml");
> $node = $dom->getElementById("id1");
> print_r($node);
> 
> Test file:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <test>
>  <el1 id="id1"/>
>  <el2 id="id2"/>
> </test>
> 
> It seems to me that always a emty object is returned?
> 

-- 
christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich
phone +41 1 240 56 70 | mobile +41 76 561 88 60  | fax +41 1 240 56 71
http://www.bitflux.ch  |  chregu@bitflux.ch  |  gnupg-keyid 0x5CE1DECB

---

## #4429 — John Huntjens — 2003-09-08T15:25:03+00:00

URL: https://externals.io/message/4427#4429 · In reply to: #4428

> > […]
> yes.
>
> see:
>
> http://bugs.php.net/bug.php?id=17629
> http://bugs.php.net/bug.php?id=16647
>
> for details

I do not understand the workaround?
I am using latest cvs php5

capitalizing the ID's to

<?xml version="1.0" encoding="utf-8"?>
<test>
 <el1 ID="id1"/>
 <el2 ID="id2"/>
</test>

gives no result.

Should I define a DTD to find the ID's?

Gr,

John


>
> chregu
>
> > […]
>
> --
> christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich
> phone +41 1 240 56 70 | mobile +41 76 561 88 60  | fax +41 1 240 56 71
> http://www.bitflux.ch  |  chregu@bitflux.ch  |  gnupg-keyid 0x5CE1DECB

---

## #4430 — Christian Stocker — 2003-09-08T15:55:03+00:00

URL: https://externals.io/message/4427#4430 · In reply to: #4429

> > […]
> 
> 
> I do not understand the workaround?
> I am using latest cvs php5

you have to define the ids with a DTD. there are no default 
"id"-attributes in the XML-specs.

Add:
<!DOCTYPE test [
<!ATTLIST el1 id ID #REQUIRED>
<!ATTLIST el2 id ID #REQUIRED>
]>

to your XML document, and it should work.

or use XPath to access the nodes:
"//@id='id1'"

chregu

> 
> capitalizing the ID's to
> 
> <?xml version="1.0" encoding="utf-8"?>
> <test>
>  <el1 ID="id1"/>
>  <el2 ID="id2"/>
> </test>
> 
> gives no result.
> 
> Should I define a DTD to find the ID's?
> 
> Gr,
> 
> John
> 
> 
> 
> > […]
> 
> 

-- 
christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich
phone +41 1 240 56 70 | mobile +41 76 561 88 60  | fax +41 1 240 56 71
http://www.bitflux.ch  |  chregu@bitflux.ch  |  gnupg-keyid 0x5CE1DECB

---

## #4432 — John Huntjens — 2003-09-08T16:41:59+00:00

URL: https://externals.io/message/4427#4432 · In reply to: #4430

<snip>

> you have to define the ids with a DTD. there are no default
> "id"-attributes in the XML-specs.

Ahh, that clarify's alot.


> Add:
> <!DOCTYPE test [
> <!ATTLIST el1 id ID #REQUIRED>
> <!ATTLIST el2 id ID #REQUIRED>
> ]>
>
> to your XML document, and it should work.

Thanks for your quick answer, this quireled me al day!

> or use XPath to access the nodes:
> "//@id='id1'"

Can you give me a pointer how to do that in php5, I thought that this was
not implemented (yet)?

Gr,

John
