Re: [PHP] DOM Element default ID attribute

2007-02-23 Thread Richard Lynch
On Wed, February 21, 2007 11:44 pm, Eli wrote:
 Peter Lauri wrote:
 This was not clear for me, do you mean:

 a peter = a id=peter


 No.

 Let me try to be more clear..
 Say you got the element elem key=peter , then I want the
 DOMDocument
 to automatically convert the 'key' attribute to an ID-Attribute, as
 done
 with DOMElement::setIdAttribute() function. The ID-Attribute is
 indexed
 and can be quickly gotten via DOMDocument::getElementById() function.

 I'm trying to avoid looping on all nodes overriding the importNode()
 and
 __construct() methods of DOMDocument.

Are the keys guaranteed to be unique?

If not, you can't do that, because the IDs have to be unique, no?

I suspect you'll simply have to walk the whole thing and do it the
hard way, if it's even a Good Idea...

You might be better off taking a step back and asking the list how
they solved whatever problem you're trying to solve with
auto-generating the IDs, as there may be a Better Way...

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DOM Element default ID attribute

2007-02-22 Thread Rob Richards

Eli wrote:

Let me try to be more clear..
Say you got the element elem key=peter , then I want the DOMDocument 
to automatically convert the 'key' attribute to an ID-Attribute, as done 
with DOMElement::setIdAttribute() function. The ID-Attribute is indexed 
and can be quickly gotten via DOMDocument::getElementById() function.


I'm trying to avoid looping on all nodes overriding the importNode() and 
__construct() methods of DOMDocument.


Add a DTD to the document defining your attribute as an ID.

$xml = EOXML
?xml version=1.0?
!DOCTYPE note [
  !ATTLIST elem key ID  #IMPLIED
]
doc
elem key=peterThis is Peter/elem
elem key=samThis is Sam/elem
elem key=mikeThis is Mike/elem
/doc
EOXML;

$dom = new DOMDocument();
$dom-loadXML($xml);

if ($elem = $dom-getElementByID(sam)) {
print $elem-textContent;
} else {
print Element not found;
}

Rob

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] DOM Element default ID attribute

2007-02-21 Thread Peter Lauri
This was not clear for me, do you mean:

a peter = a id=peter

Best regards,
Peter Lauri

www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free


-Original Message-
From: Eli [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 22, 2007 12:42 AM
To: php-general@lists.php.net
Subject: [PHP] DOM Element default ID attribute

Hi,

I want to declare a default ID attribute to all elements in the document.
For example: If an element got the attribute 'id' then I want it 
automatically to become the ID attribute of the element.
How can I do that?

-thanks!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DOM Element default ID attribute

2007-02-21 Thread Eli

Peter Lauri wrote:

This was not clear for me, do you mean:

a peter = a id=peter



No.

Let me try to be more clear..
Say you got the element elem key=peter , then I want the DOMDocument 
to automatically convert the 'key' attribute to an ID-Attribute, as done 
with DOMElement::setIdAttribute() function. The ID-Attribute is indexed 
and can be quickly gotten via DOMDocument::getElementById() function.


I'm trying to avoid looping on all nodes overriding the importNode() and 
__construct() methods of DOMDocument.


-thanks.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php