現在、SVGファイルを読み込み、解析してデータを抽出し、ドキュメントに関する特定のものを特定します。私が表示したいのは、現在のノードのレイヤートレーサビリティです。SVGからレイヤーを抽出
編集:作成するSVG文書
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(svg);
String xpathIDExp = "//g/@id";
XPathFactory xpf = XPathFactory.newInstance();
XPath xpath = xpf.newXPath();
XPathExpression expression = xpath.compile(xpathIDExp);
svgIDPaths = (NodeList)expression.evaluate(doc, XPathConstants.NODESET);
..
private void printText(String output, String errorMsg) {
String parentName = new String();
for (int i = 0; i < svgIDs.getLength(); i++) {
Node node = svgIDs.item(i);
String name = node.getNodeValue();
if (node.getNodeValue().equals(output)) {
Node parent = node.getParentNode();
parentName = node.getParentNode().getNodeValue();
}
}
}
出力とerrorMsg内容は、私が(現在のノード値とカスタムエラーメッセージ)を表示しようとしていますものです。現在のノードに親ノードを追加してレイヤーを表示したい。しかし、親ノードは、私がアクセスするすべてのノードに対してヌルです。
これを行う方法はありますか?
また、私はSVGの読み込み/解析にxPathとApache POIを使用しています。
編集:親ノードがnullで、SVGのID値にアクセスしているため、getNodeValue()がIDフィールドである必要があります。
svgIdsは、IDフィールドに基づいてxpathを使用して抽出されたすべてのノードを含むノードリストです。
編集:SVGドキュメント
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" onload="initBlackBoard(evt); initClock(evt)"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="792px" height="612px"
viewBox="0 0 792 612" enable-background="new 0 0 792 612" xml:space="preserve">
<defs>
</defs>
<symbol id="SYMBOL_1" viewBox="-16.667 -16.666 33.333 33.333">
<polygon fill="#812C24" points="16.667,-16.666 -16.667,-16.666 -16.667,16.667 16.667,16.667 "/>
</symbol>
<symbol id="Symbol_2" viewBox="-23.333 -23.334 46.667 46.667">
<path fill="#09743B" d="M23.333,0c0-12.886-10.447-23.333-23.333-23.333c-12.886,0-23.333,10.447-23.333,23.333
c0,12.887,10.447,23.333,23.333,23.333C12.886,23.333,23.333,12.886,23.333,0z"/>
</symbol>
<g id="TEXT__x26__OUTLINE">
<text transform="matrix(1 0 0 1 43.9995 42.2339)"><tspan x="0" y="0" font-family="'MyriadPro-Regular'" font-size="12">Point names that are</tspan><tspan x="0" y="14.4" font-family="'MyriadPro-Regular'" font-size="12">linked to more than one</tspan><tspan x="0" y="28.8" font-family="'MyriadPro-Regular'" font-size="12">symbol</tspan></text>
<line fill="none" stroke="#000000" stroke-miterlimit="10" x1="19.555" y1="100.778" x2="772.889" y2="100.778"/>
<line fill="none" stroke="#000000" stroke-miterlimit="10" x1="185.111" y1="15.26" x2="185.111" y2="590.815"/>
<line fill="none" stroke="#000000" stroke-miterlimit="10" x1="394" y1="15.26" x2="394" y2="590.815"/>
<line fill="none" stroke="#000000" stroke-miterlimit="10" x1="602.889" y1="15.26" x2="602.889" y2="590.815"/>
<text transform="matrix(1 0 0 1 240.7773 49.4341)"><tspan x="0" y="0" font-family="'MyriadPro-Regular'" font-size="12">Analog points that are</tspan><tspan x="0" y="14.4" font-family="'MyriadPro-Regular'" font-size="12">linked to more than once</tspan></text>
<text transform="matrix(1 0 0 1 411.2217 56.6338)" font-family="'MyriadPro-Regular'" font-size="12">Linked points to compare to csv file</text>
<text transform="matrix(1 0 0 1 626.2217 35.0337)"><tspan x="0" y="0" font-family="'MyriadPro-Regular'" font-size="12">SVG interactivity is enabled</tspan><tspan x="0" y="14.4" font-family="'MyriadPro-Regular'" font-size="12">on this display and screen</tspan><tspan x="0" y="28.8" font-family="'MyriadPro-Regular'" font-size="12">shots of what the menu items </tspan><tspan x="0" y="43.2" font-family="'MyriadPro-Regular'" font-size="12">look like are provided below</tspan></text>
</g>
<g id="Layer_2">
<g id="SYMBOL_LINK-1">
<use xlink:href="#SYMBOL_1" width="33.333" height="33.333" x="-16.667" y="-16.666" transform="matrix(1 0 0 -1 60.666 141.8896)" overflow="visible"/>
</g>
<g id="Symbol_LINK-1">
<use xlink:href="#Symbol_2" width="46.667" height="46.667" x="-23.333" y="-23.334" transform="matrix(1 0 0 -1 60.666 205.2227)" overflow="visible"/>
</g>
<text transform="matrix(1 0 0 1 101.7783 145.668)" font-family="'MyriadPro-Regular'" font-size="12">Symbol 1</text>
<text transform="matrix(1 0 0 1 101.7783 207.335)" font-family="'MyriadPro-Regular'" font-size="12">Symbol 2</text>
<g id="Value_ANALOGPOINT">
<text transform="matrix(1 0 0 1 226.2222 133.001)" font-family="'MyriadPro-Regular'" font-size="12">XXXX</text>
</g>
<g id="Value_ANALOGPOINT_1_">
<text transform="matrix(1 0 0 1 226.2222 163.001)" font-family="'MyriadPro-Regular'" font-size="12">XXXX</text>
</g>
</g>
<g id="Layer_1">
<image overflow="visible" width="261" height="232" xlink:href="Screen Shot 2016-09-09 at 1.58.34 PM.png" transform="matrix(0.63 0 0 0.63 611.2217 224.1123)">
</image>
<image overflow="visible" width="500" height="329" xlink:href="Screen Shot 2016-09-09 at 1.58.41 PM.png" transform="matrix(0.3 0 0 0.3 618.4443 119.668)">
</image>
<image overflow="visible" width="239" height="216" xlink:href="Screen Shot 2016-09-09 at 2.12.18 PM.png" transform="matrix(0.7229 0 0 0.7229 607.0547 390.7773)">
</image>
<g id="Value_Hour">
<text transform="matrix(1 0 0 1 683.999 582.6289)" font-family="'MyriadPro-Regular'" font-size="12">XX</text>
</g>
<g id="Value_Minute">
<text transform="matrix(1 0 0 1 702.1074 583.0049)" font-family="'MyriadPro-Regular'" font-size="13.2778">XX</text>
</g>
<g id="Value_Second">
<text transform="matrix(1 0 0 1 721.7773 583.0059)" font-family="'MyriadPro-Regular'" font-size="13.2778">XX</text>
</g>
<text transform="matrix(1 0 0 1 637.332 583.0049)" font-family="'MyriadPro-Regular'" font-size="12">Clock</text>
</g>
</svg>
あなたが持っているSVGの種類と、 'svgIDs'のような変数を宣言して初期化する場所を教えてください。 null値については、親ノード自身がnullか、 'getNodeValue()'だけですか? W3C DOMでは、要素ノードは常にヌルノード値を持ちます。どのDOMメソッドまたはプロパティにアクセスする必要があるかを知るには、必要なデータを説明する必要があります。 –
私はあなたの質問に答えるためにそれを更新しました。コードの2番目のビットは別のクラスにあり、svgIDはsvgIDPathsへの参照です。親ノードのオブジェクトを繰り返すことは、すべてのノードに対してnullです。 –