Tôi cần sử dụng java xpath để trả về bằng id id phần tử xml dưới dạng chuỗi.Java xpath để trả lại toàn bộ phần tử dưới dạng chuỗi
cho ...
<svg>
<g id="Background">
</g>
<g id="Outline">
<polygon fill="none" stroke="#000000" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points=" 119.813,57.875 119.188,57.87" />
</g>
<g id="Base_Colour" transform="matrix(0.25 0 0 0.25 0 0)">
<path fill="#ADB1AF" d="M112.25,208l-8,20.25l-0.5-1.75l0.75-0.5v-1.5l0.75-0.5v-1.5L106,222v-1.5l0.75-0.5v-1.5l0.75-0.5v-1.5"/>
<path fill="#625595" d="M112.25,208l5.25-14.5l30-30.25l2.25-1.5l41.5-20.5l49.75-9.5h4.25l49,3l48.75"/>
</g>
</svg>
giá trị trả về nhu cầu được ...
<g id="Outline">
<polygon fill="none" stroke="#000000" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points=" 119.813,57.875 119.188,57.87" />
</g>
Tôi có googled rộng rãi và không có gì tôi đã cố gắng đã có thể trả lại toàn bộ phần tử. Xpath là mong muốn bởi vì tôi muốn truy vấn thẻ g ở mọi cấp độ theo id.
Có lẽ sử dụng regex? http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags –
Tees - xử lý xml với regexes là công việc của ma quỷ. – jeremyjjbrown