Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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 基于搜索解析XML文件并读取父级和子级_Java_Xml_Web Services - Fatal编程技术网

Java 基于搜索解析XML文件并读取父级和子级

Java 基于搜索解析XML文件并读取父级和子级,java,xml,web-services,Java,Xml,Web Services,我有一个很大的xml文件,需要在其中查找匹配的合同号,然后需要读取父节点(包括子节点)的所有剩余元素。我正在努力寻找可行的解决方案 示例XML文件,其中我的原始文件非常大,无法在此处共享 我的要求是搜索合同,并在此基础上读取该文档下的全部值。我需要使用这些值与应用程序进行比较 ''' 701 002 直接数字合成 直接数字合成 直接数字合成 直接数字合成 直接数字合成 直接数字合成 直接数字合成 直接数字合成 直接数字合成 直接数字合成 ''' 我能弄明白。我需要遍历子集,以便遍历合同id节点

我有一个很大的xml文件,需要在其中查找匹配的合同号,然后需要读取父节点(包括子节点)的所有剩余元素。我正在努力寻找可行的解决方案

示例XML文件,其中我的原始文件非常大,无法在此处共享

我的要求是搜索合同,并在此基础上读取该文档下的全部值。我需要使用这些值与应用程序进行比较 '''


701
002
直接数字合成
直接数字合成
直接数字合成
直接数字合成
直接数字合成
直接数字合成
直接数字合成
直接数字合成
直接数字合成
直接数字合成
'''
我能弄明白。我需要遍历子集,以便遍历合同id节点

File fXmlFile = new File(inputFile);
       DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
       DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
       Document doc = dBuilder.parse(fXmlFile);
       doc.getDocumentElement().normalize();

            NodeList nList;
            NodeList nChild;
            NodeList nSubset;

            nList = doc.getElementsByTagName("Document");
            aa:
            for (int temp = 0; temp < nList.getLength(); temp++) {
                Node node = nList.item(temp);
                nChild=node.getChildNodes();

                bb:
                  for(int temp1=0;temp1<nChild.getLength();temp1++) {
                      Element element1 =  (Element) node;
                      Node node1=nChild.item(temp1);
                      System.out.println("Child nodes are:"+node1.getNodeName());
                      if (node1.getNodeName()=="Contract-Id") {
                            String nodetext=node1.getTextContent();

                            if(nodetext.equalsIgnoreCase(ContractNumber)) {
                                System.out.println("Contract number found");
                                Node element2 =  (Element) node;
                                element2=node1.getParentNode();
                                nSubset=element2.getChildNodes();
                                visitChildNodes(nSubset, "Document", listUniqueEmployeeNames,empMap);
                                //System.out.println("Child nodes are:"+empMap);
                                empMap.values().removeAll(Collections.singleton(null));
                                break;
                            }
                            break bb;   
                        }

                  }
            } 
File fXmlFile=新文件(inputFile);
DocumentBuilderFactory dbFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder=dbFactory.newDocumentBuilder();
documentdoc=dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
节点列表;
NodeList-nChild;
节点列表nSubset;
nList=doc.getElementsByTagName(“文档”);
aa:
对于(int-temp=0;temp
File fXmlFile = new File(inputFile);
       DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
       DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
       Document doc = dBuilder.parse(fXmlFile);
       doc.getDocumentElement().normalize();

            NodeList nList;
            NodeList nChild;
            NodeList nSubset;

            nList = doc.getElementsByTagName("Document");
            aa:
            for (int temp = 0; temp < nList.getLength(); temp++) {
                Node node = nList.item(temp);
                nChild=node.getChildNodes();

                bb:
                  for(int temp1=0;temp1<nChild.getLength();temp1++) {
                      Element element1 =  (Element) node;
                      Node node1=nChild.item(temp1);
                      System.out.println("Child nodes are:"+node1.getNodeName());
                      if (node1.getNodeName()=="Contract-Id") {
                            String nodetext=node1.getTextContent();

                            if(nodetext.equalsIgnoreCase(ContractNumber)) {
                                System.out.println("Contract number found");
                                Node element2 =  (Element) node;
                                element2=node1.getParentNode();
                                nSubset=element2.getChildNodes();
                                visitChildNodes(nSubset, "Document", listUniqueEmployeeNames,empMap);
                                //System.out.println("Child nodes are:"+empMap);
                                empMap.values().removeAll(Collections.singleton(null));
                                break;
                            }
                            break bb;   
                        }

                  }
            } 
File fXmlFile=新文件(inputFile);
DocumentBuilderFactory dbFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder=dbFactory.newDocumentBuilder();
documentdoc=dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
节点列表;
NodeList-nChild;
节点列表nSubset;
nList=doc.getElementsByTagName(“文档”);
aa:
对于(int-temp=0;temp对于(int temp1=0;temp1),请缩进您的代码。它当前不可读。并详细解释代码的问题。请阅读。请缩进您的代码。它当前不可读。并详细解释代码的问题。请阅读。
File fXmlFile = new File(inputFile);
       DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
       DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
       Document doc = dBuilder.parse(fXmlFile);
       doc.getDocumentElement().normalize();

            NodeList nList;
            NodeList nChild;
            NodeList nSubset;

            nList = doc.getElementsByTagName("Document");
            aa:
            for (int temp = 0; temp < nList.getLength(); temp++) {
                Node node = nList.item(temp);
                nChild=node.getChildNodes();

                bb:
                  for(int temp1=0;temp1<nChild.getLength();temp1++) {
                      Element element1 =  (Element) node;
                      Node node1=nChild.item(temp1);
                      System.out.println("Child nodes are:"+node1.getNodeName());
                      if (node1.getNodeName()=="Contract-Id") {
                            String nodetext=node1.getTextContent();

                            if(nodetext.equalsIgnoreCase(ContractNumber)) {
                                System.out.println("Contract number found");
                                Node element2 =  (Element) node;
                                element2=node1.getParentNode();
                                nSubset=element2.getChildNodes();
                                visitChildNodes(nSubset, "Document", listUniqueEmployeeNames,empMap);
                                //System.out.println("Child nodes are:"+empMap);
                                empMap.values().removeAll(Collections.singleton(null));
                                break;
                            }
                            break bb;   
                        }

                  }
            }