• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create node / org.w3c.dom.Node

 
Frank Jacobsen
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Doc before:

<soap:Envelope>
<soap:Header>
<ns2:technicalAddress>
</ns2:technicalAddress>
<ns2:serviceHeader>
<organisationIdentification>
<mainRegistrationNumber>20</mainRegistrationNumber>
<isoCountryCode>dk</isoCountryCode>
</organisationIdentification>
<erpInformation>
<erpsystem>Plexa</erpsystem>
<erpversion>1</erpversion>
</erpInformation>
<format>iso</format>
<createDateTime>2014-06-10T16:07:29.211+02:00</createDateTime>
</ns2:serviceHeader>
</soap:Header>
<soap:Body>
<ns2:payment></ns2:payment>
</soap:Body>
</soap:Envelope>




Wanted:
<soap:Envelope>
<soap:Header>
<ns2:technicalAddress>
<ipAddress>127.0.0.1</ipAddress>
</ns2:technicalAddress>
<ns2:serviceHeader>
<organisationIdentification>
<mainRegistrationNumber>20</mainRegistrationNumber>
<isoCountryCode>dk</isoCountryCode>
</organisationIdentification>
<erpInformation>
<erpsystem>Plexa</erpsystem>
<erpversion>1</erpversion>
</erpInformation>
<format>iso</format>
<createDateTime>2014-06-10T16:07:29.211+02:00</createDateTime>
</ns2:serviceHeader>
</soap:Header>
<soap:Body>
<ns2:payment></ns2:payment>
</soap:Body>
</soap:Envelope>


But the ipAddress is not added

What the f... is wrong here ?

Frank
 
Stephan van Hulst
Bartender
Posts: 5334
48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know? I can't see any code that displays the result. Please post an SSCCE.
 
Frank Jacobsen
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know, i have a print function that works... to keep it simple i havent added this method...

But i can se i get a nullpointer on this line:

nodes.item(0).appendChild(p);

But i still dont get an idea, how to add the node to <ns2:technicalAddress>

Frank
 
Stephan van Hulst
Bartender
Posts: 5334
48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So either nodes or item(0) is null. I would fix that first. Check the API for when null may be returned from methods.
 
Frank Jacobsen
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.item(0) is null, but cant find out why null, the technicalAddress is in the XML as you see.

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I recall, you don't want to work with the Document node, instead use the Document method getDocumentElement() to get an Element that will handle the getElementsByTagName correctly.

Bill
 
Frank Jacobsen
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this out, but still i get a null in the nodes.item(0)... Its not easy .. Hmmm




Frank
 
Paul Clapham
Sheriff
Pie
Posts: 20724
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is looking for a "technicalAddress" element. But there aren't any such elements in your document. You have elements whose name is "ns2:technicalAddress" so you should be using the getElementsByTagNameNS method. Make sure to use the namespace URL which belongs to the "ns2" prefix.

(You did make your parser namespace-aware, didn't you?)
 
Frank Jacobsen
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot... It works ...


 
Frank Jacobsen
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works... BUT...

This is my namespace in the XML.


This works:


But is there a way to get the targetnamespace in java ?


Frank
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic