• 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

Adding elements to existing XML doc using DOM

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My XML structure:
<OrderListing>
<Customer Id="123">
<Prod type="a">4</Prod>
<Prod type="c">8</Prod>
</Customer>
etc.
</OrderListing>
Which is the best way to add a new order to this existing XML document via DOM. It has to be checked frst if there exists already a customer with the same Id. If true a prod-element has to be added under the existing Id;
else a new Customer has to be created.
Please give me a hint
Anna
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Annabell,
I have here some sort of a direction for your request.
In order to use the powerful Document getElementById method you need a DTD and declare the Customer Id attribute to be of type ID.
IDs are XML names, so they can't start with digits.
I use Java version 1.4.
Good luck,
Dan

The Java code -

Cheers,
Dan
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Annabell,
Here is a much better version.
You might want to change the serializer.
Thanks a lot for the question

Cheers,
Dan
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic