简体   繁体   English

像字符串一样解析 xPath 并使用 jdom 创建 xml 文档

[英]Parse xPath like string and create xml document using jdom

I am trying to build some utility to create document model from a string like xpath:我正在尝试构建一些实用程序来从 xpath 之类的字符串创建文档 model:

setName(document,"college/class/student[14]@name","Rob"), setName(document,"大学/班级/学生[14]@name","Rob"),

so, this function should create nodes and attributes in the document if it doesn't exist and move on if the node already exists.因此,如果此 function 不存在,则应在文档中创建节点和属性,如果节点已存在则继续。

I am failing to validate and implement the '[14]' part, ie creating 13 blank followed with adding attribute name with value of "Rob".我无法验证和实现“[14]”部分,即创建 13 个空白,然后添加值为“Rob”的属性名称。 As, there can also be cases of因为,也可能有以下情况

setName(document,"university/college[2]/class[12]/student[14]@name","Rob")\ setName(document,"university/college[2]/class[12]/student[14]@name","Rob")\

Thanks in Advance Tirthankar提前致谢

You need a recursive parser that is able to handle the indexes.您需要一个能够处理索引的递归解析器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM