2016-12-05 92 views
1

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

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

回答

0

该做的:// 组/ groupInformation/@组ID [包含(。, '10300')] /父:: */@组名

+0

太复杂(和错误的 - 认为误报,如“包含3”)。使用'// groupInformation [@groupID ='10300']/@ groupName'。 – Tomalak

2

取而代之的是怎么回答here

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

我建议,

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

因为

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