I am using dom pasrer to create xml document where tag name start with digit. and it is giving exception. seems with java DOM parser , it is not allowed to have tagname starting with digit.
Same thing ,It is achievable in C#(dot-net) using System.Xml;
is there any way, i can achieve the same.
below is the more progrom and output:
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class WriteXMLFile {
public static void main(String argv[]) {
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
// root elements
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("company");
doc.appendChild(rootElement);
Element firstname = doc.createElement("1name");
firstname.appendChild(doc.createTextNode("yong"));
rootElement.appendChild(firstname);
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
}
}
}
Exception :
Exception in thread "main" org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createElement(CoreDocumentImpl.java:618)
at com.impetus.avatar.WriteXMLFile.main(WriteXMLFile.java:25)