You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Anthony Ikeda <an...@proxima-tech.com.au> on 2001/05/15 00:57:19 UTC

Replacing nodes on a DTD XML file

I have not found anything that really helps answer this question in the
mailing list archives:

* I have an XML based config file with a DTD.
* I parse the document into my app, select a node out as an element, update
the element and want it to replace the old node.
* If I use removeChild() followed by appendChild(), it justs adds the node
at the end of the document and the parser seems to see this as valid but
according to the DTD it's not valid.
* I understand according to spec, "it is not allowed to alter neither the
document element nor the document type in any way" but this doesn't make it
very dynamic. Or do I make a whole new DocumentImpl to replace the old?

here is my code:
 public static void saveTheQuestion(Object obj){
    //load the config into a DocumentOmpl object
    org.w3c.dom.Document doc = parseDoc("config.xml");

    org.w3c.dom.Element questions = (Element)
    doc.getElementsByTagName("Questions").item(0);

    org.w3c.dom.Element questionElement = doc.createElement("Question");
//create a new element to add to config

 //modify Element...

    //add new element to original questions element
    questions.appendChild(questionElement);

    //try and put the new set of questions onto the main config doc
    doc.getDocumentElement().removeChild(questions,)
    doc.getDocumentElement().appendChild(questions);

    try{
      //Save the new config to disk.
    } catch(IOException ioe){
      System.out.println(ioe);
    }
  }

How can I correct this?

Cheers,
Anthony Ikeda
Web Application Developer,
Proxima Technology Pty. Ltd.

North Sydney
New South Wales,
Australia 2060
Office: (612) 9458 1718
Mobile: 041 624 5143



---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org