zoukankan      html  css  js  c++  java
  • 解决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

  • 相关阅读:
    Web测试与App测试的区别-总结篇
    Shell之基本用法
    Samba服务部署
    Linux基础(3)
    linux基础(2)
    linux基础(2)
    Linux基础(1)
    网络基础及网络协议
    操作系统简介
    计算机基础重要性
  • 原文地址:https://www.cnblogs.com/ae6623/p/4416249.html
Copyright © 2011-2022 走看看