logo       

Re: [xmlc] 2.3beta getElementById() behavior: msg#00017

java.enhydra.xmlc

Subject: Re: [xmlc] 2.3beta getElementById() behavior

Quoting Erik Rasmussen <rasmussenerik@xxxxxxxxx>:

> On Jan 24, 2007, at 6:37 AM, Jacob Kjome wrote:
> > Can you expand on what you mean by "attempting to look it up by its
> > new id elsewhere"?
>
> I'm importing a node from one page into another.
>
> page 1:
> -----
> <page1>
> <node id="wherePage2ContentGoes"></node>
> </page1>
> -----
>
> page 2:
> -----
> <page2>
> <node id="content">
> Stuff to be transferred to page1.
> <node id="needToMatch">this node</node>
> </node>
> </page2>
> -----
>
> // import content from page 2
> Node destNode = page1.getElementById("wherePage2ContentGoes");
> Node srcNode = page2.getElementById("content");
> destNode.appendChild(page1.importNode(srcNode, true));
>
> ...
>
> // then later:
> Node match = page1.getElementById("needToMatch"); // fails (match ==
> null)
>

I find it curious that it wouldn't be found. Which DOM implementation are you
using? If it's the HTML DOM, then I'm a little baffled. If it's the XHTML
DOM, that would make more sense. XMLC's XercesHTMLDOMParser sets attributes
with the name "id" as being of type "ID". The fact that you a node into the
XMLC-loaded DOM and can't find the Id using getElemementById("myId") tells me
that the document was probably loaded external to XMLC as HTML, but the
XMLC-loaded DOM might be XHTML. The XHTML DOM only recognizes Id's when they
are registered as being of type "ID". The HTML DOM falls back to traversing
the DOM looking for an element with an attribute named "id" with the value you
are looking for.

First, can you tell me which DOM you are using for both XMLC and for the loading
of the "page2" document? Second, if you are using the XHTML DOM for XMLC
loading, try using the HTML DOM instead and see if it works then.

> // but a full node traversal works:
> XPathExpression query = XPathFactory.newInstance().newXPath().compile
> ("//*[@id='needToMatch']");
> match = ((NodeList) query.evaluate(page1,
> XPathConstants.NODESET)).item(0); // succeeds
>
> > >Will it be possible to update the cache when element.setId() is
> > >called? If not, can I disable this caching?
> > >
> >
> > I have to look into this, but don't have time tonight. Can you try
> > XMLC-2.2.13 and verify that what you are trying to do works there?
>
> It seems to be broken in XMLC-2.2.13 too. I was using XMLC-2.2.8
> back when it was working.
>

Both the HTML and XHTML DOM's were using an unoptimized method for looking up
Id's in getElementById() before 2.2.13 (or was it 2.2.12? Can't recall?). So,
there are certain scenarios where it would make sense that things might not work
(detailed above).

> Is there a better solution than using xpath? It seems like importNode
> () should add all the new id's into its id-to-node map, no?
>

If you are using the XHTML DOM for XMLC-loaded templates and the HTML DOM for
templates containing the node you are importing, you might need to register
elements with the Id you care about as of type "ID", using
element.setIdAttribute() [1].

[1] http://xerces.apache.org/xerces2-j/faq-dom.html#faq-14

> Erik


Jake



--
You receive this message as a subscriber of the xmlc@xxxxxxxxxxxxx mailing list.
To unsubscribe: mailto:xmlc-unsubscribe@xxxxxxxxxxxxx
For general help: mailto:sympa@xxxxxxxxxxxxx?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise