• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Create node / org.w3c.dom.Node

 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.item(0) is null, but cant find out why null, the technicalAddress is in the XML as you see.

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot... It works ...


 
Frank Jacobsen
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic