XPath,获取XML元素中的下一个属性
这个XPath表达式 //groups/groupInformation/@groupID[包含(,'10300')] 执行从groupID获取“10300”的任务(见下文)。但是,如何从groupName、groupDescription等获取文本?想要检索“卡内尔-布朗”等等。在我描述这个问题时,我不确定是否正确使用了“元素”和“属性”XPath,获取XML元素中的下一个属性,xml,xpath,Xml,Xpath,这个XPath表达式 //groups/groupInformation/@groupID[包含(,'10300')] 执行从groupID获取“10300”的任务(见下文)。但是,如何从groupName、groupDescription等获取文本?想要检索“卡内尔-布朗”等等。在我描述这个问题时,我不确定是否正确使用了“元素”和“属性” <groupInformation groupID="10300" groupName="Carnell - Brown" groupDescript
<groupInformation groupID="10300" groupName="Carnell - Brown" groupDescription="The comfortable contemporary design of the “Carnell-Walnut” upholstery collection features deeply stitched back cushioning and shaped chaise seating all surrounded with soft faux leather fabric which offers the beauty and character of leather to create the ultimate collection for any home." groupStyle="Contemporary" groupFeatures="Frame constructions have been tested with various equipment to simulate the home and transportation environments to insure durability. Corners are glued, blocked and stapled. All fabrics are pre-approved for wearability and durability against AHFA standards. Cushion cores are constructed of low melt fiber wrapped over high quality foam. Features metal drop-in unitized seat box for strength and durability. All metal construction to the floor for strength and durability. The reclining mechanism features infinite positions for comfort. Heavyweight faux leather upholstery fabric. Jumbo thread stitched detailing. Collection features the option of either power or non-power pieces." />
这样做:
//groups/groupInformation/@groupID[包含(,'10300')]/parent::*/@groupName而不是回答什么 我建议,
//groups/groupInformation[@groupID='10300']/@groupName
因为
- 它更简洁
- 当
为10300999或9991030时,可以避免错误匹配@groupID
//groupInformation[@groupID='10300']/@groupName
。
//groups/groupInformation[@groupID='10300']/@groupName