質問

JDOMと解析するXMLドキュメントがあり、XPath式を満たすすべてのノードを取得しようとしますが、XPathは常に要素を返しません。これが私のXMLファイルです:

<?xml version="1.0" encoding="UTF-8"?>

<!-- Using aggregate instance. Should pass -->

<pnml xmlns="http://www.pnml.org/version-2009/grammar/pnml">
    <net id="rootAgregate" type="http://www.cs.stu.cn.ua/jess/enets">
        <page id="main">
            <transition id="agregate1">
                <name>
                    <text>agregate1</text>
                    <graphics>
                        <offset x="22" y="-14"/>
                    </graphics>
                </name>
                <definition type="aggregate" subType="myAggregate"/>
                <graphics>
                    <position x="950" y="484"/>
                </graphics>
            </transition>
            <transition id="Input1">
                <name>
                    <text>agregate1</text>
                    <graphics>
                        <offset x="22" y="-14"/>
                    </graphics>
                </name>
                <definition type="input"/>
                <graphics>
                    <position x="950" y="484"/>
                </graphics>
            </transition>
            <transition id="Output1">
                <name>
                    <text>agregate1</text>
                    <graphics>
                        <offset x="22" y="-14"/>
                    </graphics>
                </name>
                <definition type="output"/>
                <graphics>
                    <position x="950" y="484"/>
                </graphics>
            </transition>
        </page>
    </net>
</pnml>

これが私のXathコードです:

private List<String> getChildNames(Document parsedDom) throws JDOMException {
        ArrayList<String> childNames = new ArrayList<String>();
        XPath childCounter = XPath.newInstance("//definition[@type=\"aggregate\"]");
        ListIterator<Element> listIterator = childCounter.selectNodes(parsedDom).listIterator();

        while (listIterator.hasNext()) {
            Element definitionElement = listIterator.next();
            childNames.add(definitionElement.getAttributeValue("subType"));
        }

        return childNames;
    }

ここでXpathの式を確認しました:http://www.whitebeam.org/library/guide/technotes/xpathtestbed.rhtmそしてそれは機能します。

なぜ私のコードで機能しないのですか?

前もって感謝します。

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top