You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Stefan Pietschmann <sp...@inf.tu-dresden.de> on 2005/01/04 09:25:28 UTC
getElementById in request does not work
Hi there,
I'm writing my custom action, and this is my problem with it:
I fetch a parameter from the request (which is sent with a form). It
contains an small rdf snippet. I thought I'd be able to read it out with
getelementbyid, but it doesn't work. The request parameter looks like this:
<RDF>
<Description id="Profile">
<component>
<Description id="UserInteraction">.</Description>
</component>
<component>
<Description id="SoftwarePlatform">.</Description>
</component>
<component>
<Description id="HardwarePlatform">.</Description>
</component>
<component>
<Description id="BrowserUA">.</Description>
</component>
</Description>
</RDF>
And my code looks like this (shortened):
######################################
// requestParameterID is the name of the request parameter
// get the request
Request request = ObjectModelHelper.getRequest(objectModel);
// now build a document from the rdf in the request
factory = DocumentBuilderFactory.newInstance();
// requestParam should now be the xml from above
requestParam = factory.newDocumentBuilder().parse(
new InputSource(new
StringReader(request.getParameter(requestParameterID))));
// now I should be able to do something like this, right?
requestParam.getElementsById("UserInteraction");
#######################################
--> this returns null. Why?
If I iterate through all Elements, I find it though (like this:)
#######################################
NodeList descriptions = requestParam.getElementsByTagName("Description");
String thisID;
for (int a = 0; a < descriptions.getLength(); a++) {
if ((thisID =
descriptions.item(a).getAttributes().getNamedItem("id").getNodeValue()) !=
null) {
if (thisID.equals("UserInteraction")) {
System.out.println("found userinteraction");
}
}
}
########################################
So I do find the right element and it does exist, but why can't I use
getElementById instead of going through all elements?
Thanx,
Stefan
AW: getElementById in request does not work
Posted by Stefan Pietschmann <sp...@inf.tu-dresden.de>.
Thanx, I was expecting something like that, but I thought there'd be an easy
way to somehow specify the ID attribute at document generation.
Since I generate the requests I'm gonna try it with xml:id - hopefully this
will work.
Cheers,
Stefan
-----Ursprüngliche Nachricht-----
Von: Christian Stocker [mailto:chregu@bitflux.ch]
Gesendet: Dienstag, 4. Januar 2005 10:27
An: dev@cocoon.apache.org
Cc: cocoon-dev@apache.org
Betreff: Re: getElementById in request does not work
Hi
On 4.1.2005 9:25 Uhr, Stefan Pietschmann wrote:
> Hi there,
>
> I'm writing my custom action, and this is my problem with it:
>
> I fetch a parameter from the request (which is sent with a form). It
> contains an small rdf snippet. I thought I'd be able to read it out with
> getelementbyid, but it doesn't work. The request parameter looks like
this:
Maybe this helps a little bit:
http://blog4.bitflux.ch/wiki/GetElementById_Pitfalls
(It's written for PHP, but the problem applies to other languages as
well...)
chrgeu
>
> <RDF>
> <Description id="Profile">
> <component>
> <Description id="UserInteraction">.</Description>
> </component>
> <component>
> <Description id="SoftwarePlatform">.</Description>
> </component>
> <component>
> <Description id="HardwarePlatform">.</Description>
> </component>
> <component>
> <Description id="BrowserUA">.</Description>
> </component>
> </Description>
> </RDF>
>
> And my code looks like this (shortened):
>
> ######################################
>
> // requestParameterID is the name of the request parameter
>
> // get the request
> Request request = ObjectModelHelper.getRequest(objectModel);
>
> // now build a document from the rdf in the request
> factory = DocumentBuilderFactory.newInstance();
> // requestParam should now be the xml from above
> requestParam = factory.newDocumentBuilder().parse(
> new InputSource(new
> StringReader(request.getParameter(requestParameterID))));
>
> // now I should be able to do something like this, right?
> requestParam.getElementsById("UserInteraction");
>
> #######################################
>
> --> this returns null. Why?
>
> If I iterate through all Elements, I find it though (like this:)
>
> #######################################
>
> NodeList descriptions = requestParam.getElementsByTagName("Description");
> String thisID;
> for (int a = 0; a < descriptions.getLength(); a++) {
> if ((thisID =
> descriptions.item(a).getAttributes().getNamedItem("id").getNodeValue()) !=
> null) {
> if (thisID.equals("UserInteraction")) {
> System.out.println("found userinteraction");
> }
> }
> }
> ########################################
>
> So I do find the right element and it does exist, but why can't I use
> getElementById instead of going through all elements?
>
> Thanx,
> Stefan
>
--
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
Re: getElementById in request does not work
Posted by Christian Stocker <ch...@bitflux.ch>.
Hi
On 4.1.2005 9:25 Uhr, Stefan Pietschmann wrote:
> Hi there,
>
> I'm writing my custom action, and this is my problem with it:
>
> I fetch a parameter from the request (which is sent with a form). It
> contains an small rdf snippet. I thought I'd be able to read it out with
> getelementbyid, but it doesn't work. The request parameter looks like this:
Maybe this helps a little bit:
http://blog4.bitflux.ch/wiki/GetElementById_Pitfalls
(It's written for PHP, but the problem applies to other languages as
well...)
chrgeu
>
> <RDF>
> <Description id="Profile">
> <component>
> <Description id="UserInteraction">.</Description>
> </component>
> <component>
> <Description id="SoftwarePlatform">.</Description>
> </component>
> <component>
> <Description id="HardwarePlatform">.</Description>
> </component>
> <component>
> <Description id="BrowserUA">.</Description>
> </component>
> </Description>
> </RDF>
>
> And my code looks like this (shortened):
>
> ######################################
>
> // requestParameterID is the name of the request parameter
>
> // get the request
> Request request = ObjectModelHelper.getRequest(objectModel);
>
> // now build a document from the rdf in the request
> factory = DocumentBuilderFactory.newInstance();
> // requestParam should now be the xml from above
> requestParam = factory.newDocumentBuilder().parse(
> new InputSource(new
> StringReader(request.getParameter(requestParameterID))));
>
> // now I should be able to do something like this, right?
> requestParam.getElementsById("UserInteraction");
>
> #######################################
>
> --> this returns null. Why?
>
> If I iterate through all Elements, I find it though (like this:)
>
> #######################################
>
> NodeList descriptions = requestParam.getElementsByTagName("Description");
> String thisID;
> for (int a = 0; a < descriptions.getLength(); a++) {
> if ((thisID =
> descriptions.item(a).getAttributes().getNamedItem("id").getNodeValue()) !=
> null) {
> if (thisID.equals("UserInteraction")) {
> System.out.println("found userinteraction");
> }
> }
> }
> ########################################
>
> So I do find the right element and it does exist, but why can't I use
> getElementById instead of going through all elements?
>
> Thanx,
> Stefan
>
--
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