• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

DOM-problems

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Im using this examplecode below to update an xml file with a new value. It works not so good. I therefor submiting this list and hopefully someone can help.

1. Im having problems to add an attribiute to my elemenst, Im keep getting the error "HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted". I think the idAtt2 is the right way to go, but how to append it?

2. If I comment the attr-part, the new data will end upp in my xmlfile. However there will be NONE indent even when I submit "yes". Why is that?

3. Finally, if some errors will come up it often result in an empty xmlfile. Thats no good, so if you have an better way to update an ceratin xml file with indent and the data is stored. Pls let me know.

 
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
Yes, you are using it wrong. Look at the org.w3c.dom.Element documentation for the setAttributeNode( ) and related methods. An Attr can't be the child of another Node.

Bill
 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I mange to solve the Attr, thanks for the tip. I was looking around in the org.w3c.dom.Node instead of org.w3c.dom.Element.

But I still have the INDENT problem, all the new element are positioned as the root element. Any clue?
[ September 03, 2004: Message edited by: Sebastian Green ]
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not use Element#setAttribute(String, String) instead?
 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thx Lasse. I thougth I would edit the post instead post a new, but as I mention I done with the Element interface. But still, the indent problem. grrr.
 
William Brogden
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
I can't see anywhere in your code that you log or System.println() any indication that the code path which is supposed to do the setOutputProperty is actually taken. Perhaps it is never called.
Bill
 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
out = new BufferedWriter(new PrintWriter(new FileWriter(usersXMLpath))) is where is save alla the data. I added some setOutputProperty and the resulted in that alla the nodes where indented but the first!

myTransformer.setOutputProperty(OutputKeys.METHOD, "xml");
myTransformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
myTransformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
 
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic