Új hozzászólás Aktív témák

  • smallmer

    őstag

    válasz smallmer #12255 üzenetére

    Sziasztok!

    még mindig próbálom megoldani ezt a feladatot.

    Eddig jutottam, de sajnos semmit nem rak bele a topics NodeList-embe.
    Mi lehet a gond?

    import java.io.FileNotFoundException;
    import java.io.FileReader;

    import javax.xml.xpath.XPath;
    import javax.xml.xpath.XPathConstants;
    import javax.xml.xpath.XPathExpressionException;
    import javax.xml.xpath.XPathFactory;

    import org.w3c.dom.Element;
    import org.w3c.dom.NodeList;
    import org.xml.sax.InputSource;

    public class XPathDriver01 {

    static NodeList topics;

    public static void main(String[] args) throws XPathExpressionException, FileNotFoundException {
    XPath xPath = (XPathFactory.newInstance().newXPath());
    System.out.println("Valami1");
    displayTopicNames(xPath);
    System.out.println(topics.getLength());
    }

    public static void displayTopicNames(XPath xPath) throws XPathExpressionException, FileNotFoundException {
    topics = (NodeList) xPath.evaluate("s:complexType/s:sequence/s:element", new InputSource(new FileReader("valami.xml")), XPathConstants.NODESET);
    System.out.println(topics.getLength());
    for (int i = 0; i < topics.getLength(); i++) {
    System.out.println(" |____" + ((Element) topics.item(i)).getAttribute("name"));
    }
    }

    }

Új hozzászólás Aktív témák

Hirdetés