Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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 Parsing - Fatal编程技术网

用Java解析XML文件

用Java解析XML文件,java,xml-parsing,Java,Xml Parsing,我需要用Java解析am XML文件,并根据条件检查一些支持。我试着用DOM来做这个 <Config> <Configuration> <Descriptor> <e id="0"> <family>Rest</family> <supportedList> <_length>

我需要用Java解析am XML文件,并根据条件检查一些支持。我试着用DOM来做这个

  <Config>
      <Configuration>
        <Descriptor>
          <e id="0">
            <family>Rest</family>
            <supportedList>
              <_length>5</_length>
              <_type>TypeX[]</_type>
              <e id="0">value-1</e>
              <e id="1">value-2</e>
              <e id="2">value-3</e>
              <e id="3">value-4</e>
              <e id="4">value-5</e>
            </supportedList>
          </e>
          <e id="1">
            <family>Rest1</family>
            <supportedList>
              <_length>5</_length>
              <_type>TypeX[]</_type>
              <e id="0">value1-1</e>
              <e id="1">value1-2</e>
              <e id="2">value1-3</e>
              <e id="3">value1-4</e>
              <e id="4">value1-5</e>
            </supportedList>
          </e>
          </Descriptor>
      </Configuration>
    </Config>

休息
5.
TypeX[]
价值-1
价值-2
价值-3
价值-4
价值-5
Rest1
5.
TypeX[]
价值1-1
价值1-2
价值1-3
价值1-4
价值1-5
在上面的XML文件中,我需要遍历“e”块和描述符块,然后搜索Family-Rest1,然后遍历supportedList。检查supportedList是否包含用户提供的值(如果存在),然后返回true

我尝试使用DOM解析器,但无法正确解析文件。我正在处理的实际XML文件有20K行,数据太多。任何简单的解决办法

    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    xPathExpression = xpath.compile("//family[text()='Rest1']/e");

    NodeList list = (NodeList) xPathExpression
        .evaluate(xml, XPathConstants.NODESET);

在XPath语法方面,搜索“XPath备忘单”就足够了。

告诉我们您到目前为止都做了哪些尝试。XPath比DOM更好,因为实际文件中有相当敏感的数据,我在代码中也使用了同样的数据,因此无法共享代码。可能重复