Java Reference
In-Depth Information
Element root = doc.createElement("movie");
doc.appendChild(root);
// Create name child element and add it to the
root.
Element name = doc.createElement("name");
root.appendChild(name);
// Add a text element to the name element.
Text text = doc.createTextNode("Le Fabuleux Destin
d'Amélie Poulain");
name.appendChild(text);
// Create language child element and add it to the
root.
Element language = doc.createElement("language");
root.appendChild(language);
// Add a text element to the language element.
text = doc.createTextNode("français");
language.appendChild(text);
System.out.println("Version
=
"+doc.getXmlVersion());
System.out.println("Encoding
=
"+doc.getXmlEncoding());
System.out.println("Standalone
=
"+doc.getXmlStandalone());
System.out.println();
NodeList nl = doc.getChildNodes();
for (int i = 0; i < nl.getLength(); i++)
{
Node node = nl.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE)
dump((Element) node);
}
}
catch (FactoryConfigurationError fce)
{
System.err.println("FCE: "+fce);
}
Search WWH ::




Custom Search