Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
你好,
我正在尝试使用 xpath 在 XML 中设置特定元素。我需要它位于特定位置,例如 /UIM/INVOICE/SECTION/RECORD* [i+1] *
我需要使用“position()”方法来做到这一点吗?或者我该怎么做?
谢谢
如果您在运行时构造 XPath 表达式并且您有一个以 1 开头的整数值,您可以简单地将该值放在谓词中,例如int pos = i + 1; String path = "/UIM/INVOICE/SECTION/RECORD[" + pos + "]";。这将选择*pos*thRECORD子元素。
int pos = i + 1; String path = "/UIM/INVOICE/SECTION/RECORD[" + pos + "]";
RECORD