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 | [EMAIL PROTECTED] | gnupg-keyid 0x5CE1DECB
