Adding Content to DOM

Hi,
I have a beginner question.
I create a DTD and read a document in that conforms to the DTD. The
content model
allows me to add a names element like this.

Element element = doc.createElement("names");

and then add text nodes to that element

 element.appendChild(doc.createTextNode ("Eric Richardson"));
root.appendChild(element); // add the element

In this model names is optional (names?) so I can read the doc in
without it using strict parsing
but then add a names element. Then I can add many text nodes to my names
tag,
names (#PCDATA)* so I can add many names.

<mydoc>
  <some-tag />
  <names>
  Eric Richardson
  other names ...
</names>
</mydoc>

Is there a simple way to make sure that the document is valid when I add
elements to it in memory?
Hopefully in a portable way.

Thanks
Eric

Received on Friday, 3 March 2000 12:42:53 UTC