Symbol '#' in XML attribute name produses DOMException
- by kilonet
the following code (using iText library):
PdfStamper stamp = new PdfStamper(reader, outputStream);
AcroFields form = stamp.getAcroFields();
String name = "form1[0].#subform[0].Table1[0].#subformSet[0].Row[2].#field[0]";
form.setField(name, "");
produces the following error:
org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.checkQName(CoreDocumentImpl.java:2571)
at com.sun.org.apache.xerces.internal.dom.ElementNSImpl.setName(ElementNSImpl.java:117)
at com.sun.org.apache.xerces.internal.dom.ElementNSImpl.<init>(ElementNSImpl.java:80)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createElementNS(CoreDocumentImpl.java:2084)
at com.lowagie.text.pdf.XfaForm$Xml2SomDatasets.insertNode(Unknown Source)
at com.lowagie.text.pdf.AcroFields.setField(Unknown Source)
at com.lowagie.text.pdf.AcroFields.setField(Unknown Source)
obviously this is because of '#' sign in field name. This field's name come from AcroFields.getFields() collection and it seems very strange that setting back this value produces an error.
Are there any ways of dealing with this error without changing real field name?