Author |
Message
|
geethgubi |
Posted: Thu Jan 08, 2009 12:32 pm Post subject: Accessing XML element in Java compute node |
|
|
Apprentice
Joined: 18 Dec 2008 Posts: 44
|
I have the following xml (sample) with namespaces
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:m="...." xmlns:n="....">
<env:Header>
.... </env:Header>
<env:Body>
<tns:Cust xmlns:tns="...." xsi:schemaLocation=".....">
<tns:a>abcd/tns:a>
<tns:b>123456</tns:b>
<tns:c>xyz</tns:c>
<tns:d>pqr</tns:d>
</tns:Cust>
</env:Body>
</env:Envelope>
I would like to access the value of the element env:Envelope.env:Body.tns:Cust.tns:a in Java compute node. Can somebody pls help out with the solution to this asap. Thanks |
|
Back to top |
|
 |
kimbert |
Posted: Thu Jan 08, 2009 3:20 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
What have you tried, and what happened when you tried it? |
|
Back to top |
|
 |
geethgubi |
Posted: Thu Jan 08, 2009 3:33 pm Post subject: |
|
|
Apprentice
Joined: 18 Dec 2008 Posts: 44
|
I have tried
MbElement msgTxtElement = body.getFirstElementByPath("/XML/env:Envelope/env:Body/tns:Cust/tns:a");
not the exact string as above. I modified tns:Cust/tns:a as per my actual xml. But I couldnt test this at all as I am getting some error with deployment. But no one is here to tell me whether it is correct or not. |
|
Back to top |
|
 |
kimbert |
Posted: Fri Jan 09, 2009 1:52 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
|
Back to top |
|
 |
geethgubi |
Posted: Fri Jan 09, 2009 5:05 am Post subject: |
|
|
Apprentice
Joined: 18 Dec 2008 Posts: 44
|
I know that XML is the deprecated domain and we should use XMLNS. But I need the sample code to achieve it. Pls let me know if you find any. Thanks. |
|
Back to top |
|
 |
kimbert |
Posted: Fri Jan 09, 2009 5:13 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
No, you should not use XMLNS. You should use XMLNSC ( assuming that you are on v6.0 or later ).
The XML domain does not support namespaces.
Your document has namespaces.
So you will never get it working with the XML domain.
There is no need for sample code - this is a very simple task. Your next step is to switch to XMLNSC and try again. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Jan 09, 2009 5:15 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
The code you showed will work for accessing a message element regardless of what parser the message is described by. Although you must adjust your path string to include the name of the parser that is being used.
And again, the parser that should be used is XMLNSC, not XML, and not XMLNS.
And there's *lots* of sample code in various posts in this forum. Have you looked for it? |
|
Back to top |
|
 |
|