XPath,获取XML元素

时间:2016-12-05 20:29:23

标签: xml xpath

这个XPath表达式 // groups / groupInformation / @ groupID [contains(。,'10300')] 从groupID获取“10300”的工作(见下文)。但是,我如何从groupName,groupDescription等获取文本?想要检索“卡内尔 - 布朗”等。当我描述这个问题时,我不确定我是否正确使用“元素”和“属性”。

<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." />

2 个答案:

答案 0 :(得分:2)

而不是回答here

//groups/groupInformation/@groupID[contains(., '10300')]/parent::*/@groupName

我建议,

//groups/groupInformation[@groupID='10300']/@groupName

,因为

  • 它更简洁。
  • @groupID为10300999或9991030 ...
  • 时,您将避免错误匹配

答案 1 :(得分:0)

这样做: // groups / groupInformation / @ groupID [contains(。,'10300')] / parent :: * / @ groupName