解决java写入xml报错org.w3c.dom.DOMException:DOM002 Illeg

Exception is -- > org.w3c.dom.DOMException: DOM002 Illegal character 字符不被允许

org.w3c.dom.DOMException: DOM002 Illegal character

        at org.apache.xerces.dom.DocumentImpl.createAttribute(DocumentImpl.java:466)

        at org.apache.xerces.dom.ElementImpl.setAttribute(ElementImpl.java:449)

        at WriteXML.main(WriteXML.java:33)


说明你的xml节点可能有空格/分号/逗号/单引号了 

错误:【Element wfmNode = doc.createElement("wfm-node';/' ");】

正确:【Element wfmNode = doc.createElement("wfm-node");】

xml规范中不允许出现空格的!


实例代码:

for(int i=0;i<bindWfmNodes.size();i++){

BindWfmNodeModel wfmB = (BindWfmNodeModel)bindWfmNodes.get(i); 

Element wfmNode = doc.createElement("wfm-node");

wfmNodes.appendChild(wfmNode);

//wfm-node-activityId

Element wfmActivityId = doc

.createElement("wfm-node-activityId");

wfmActivityId.appendChild(doc

.createTextNode(wfmB.getWfmActivityId()));

//wfm-node-name

Element wfmFieldName = doc.createElement("wfm-field-name");

wfmFieldName.appendChild(doc

.createTextNode(wfmB.getName()));


//wfm-node-fieldBindKey

Element wfmBindFieldKey = doc.createElement("wfm-bind-field-key");

wfmBindFieldKey.appendChild(doc.createTextNode(wfmB.getBindFieldKey()));

wfmNode.appendChild(wfmActivityId);

wfmNode.appendChild(wfmFieldName);

wfmNode.appendChild(wfmBindFieldKey);

}

form.appendChild(wfmNodes);


落雨

2015年2月2日18:25:32

QQ 394263788

你可能感兴趣的:(exception)