Using Java to parse XML

后端 未结 7 757
忘了有多久
忘了有多久 2020-12-21 07:23

I have made a PHP script that parses an XML file. This is not easy to use and I wanted to implement it in Java.

Inside the first element there are various count of

7条回答
  •  春和景丽
    2020-12-21 07:52

    The Java APIs, while giving you everything you need, are pretty ridiculous to use as you can see. You might check out Xsylum for something more straightforward:

    (Guessing how your XML is structured):

    List elements = Xsylum.elementFor(xmlFile).getAll("wfs:member");
    for (XmlElement e : elements)
      String dataType = e.get("omso").get("om").attribute("xlink");
    

    As suggested elsewhere, you also might want to just use XPath to extract what you're after, which is also straightforward with Xsylum:

    List values = Xsylum.documentFor(xmlFile).values("//omso/om/@href");
    

提交回复
热议问题