cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stefan Pietschmann" <sp186...@inf.tu-dresden.de>
Subject getElementById in request does not work
Date Tue, 04 Jan 2005 08:25:28 GMT
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



Mime
View raw message