Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何解决org.xml.sax.SAXException_Java - Fatal编程技术网

Java 如何解决org.xml.sax.SAXException

Java 如何解决org.xml.sax.SAXException,java,Java,我得到一个错误: org.xml.sax.SAXException: expected </taxonomy> org.xml.sax.SAXException:应为 我正在创建用于创建父子关系的xml。 我的代码: public void createXML(Map mp) throws SAXException, TransformerConfigurationException{ System.out.println("the size of the mp is

我得到一个错误:

org.xml.sax.SAXException: expected </taxonomy>
org.xml.sax.SAXException:应为
我正在创建用于创建父子关系的xml。 我的代码:

public void createXML(Map mp) throws SAXException, TransformerConfigurationException{

System.out.println("the size of the mp is              :   "+mp.size());
String parent,child,li,child1;
  li = "li";
Set keySetFinal = mp.keySet();
System.out.println("the size of the key set is : "+keySetFinal.size());
// Get Iterator of keySet
Iterator<String> iterator = keySetFinal.iterator(); 
XMLDocument xml = new XMLDocument(new StreamResult("C:\\Program Files\\Notepad++\\XML_FOR_TAX.xml"), false, 4, null);
  xml.startDocument();
  {
    try {
        xml.startElement("taxonomy");

      while(iterator.hasNext()){          
            //  System.out.println("loop started");
            parent = iterator.next();
            NodeList childNodes = (NodeList) mp.get(parent);
            System.out.println("the size of the child list for this iteration is: "+ childNodes.getLength());
            xml.addElement("li", parent);
            System.out.println("key in the xml creation function is: "+parent);

                for (int i = 0; i < childNodes.getLength(); i++){
                     if (childNodes.item(i).getNodeType() == Node.ELEMENT_NODE){
                     Element child_1 = (Element)childNodes.item(i); 
                     child1 = child_1.getAttribute("name");
                     System.out.println("child now is : "+child1);
                     xml.startElement("ul");
                     xml.addElement("li", child1);
                     xml.endElement("ul");
                     }                     
                     }
                xml.endElement("li");
      }



    }catch (SAXException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
    xml.endElement("taxonomy"); 
            }
      xml.endDocument();
  }
public void createXML(Map mp)抛出SAXException、TransformerConfiguration异常{
System.out.println(“mp的大小为:“+mp.size()”);
字符串parent、child、li、child1;
li=“li”;
Set keySetFinal=mp.keySet();
System.out.println(“密钥集的大小为:“+keySetFinal.size()”);
//获取键集的迭代器
迭代器迭代器=keySetFinal.Iterator();
XMLDocument xml=new XMLDocument(new StreamResult(“C:\\Program Files\\Notepad++\\xml\u FOR_TAX.xml”),false,4,null);
xml.startDocument();
{
试一试{
startElement(“分类法”);
while(iterator.hasNext()){
//System.out.println(“循环启动”);
parent=iterator.next();
节点列表子节点=(节点列表)mp.get(父节点);
System.out.println(“此迭代的子列表的大小为:”+childNodes.getLength());
addElement(“li”,父元素);
System.out.println(“xml创建函数中的键为:“+parent”);
对于(int i=0;i
请同时发布您的XML。Alex:我想创建XML,XML不是我的输入。Piyush:我试着将结束元素(分类法)放在catch之前,但没有成功
XMLDocument
的完全限定类名是什么?代码中的哪个语句引发异常?请编辑您的帖子并包含整个stacktrace。