Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XPath,获取XML元素中的下一个属性_Xml_Xpath - Fatal编程技术网

XPath,获取XML元素中的下一个属性

XPath,获取XML元素中的下一个属性,xml,xpath,Xml,Xpath,这个XPath表达式 //groups/groupInformation/@groupID[包含(,'10300')] 执行从groupID获取“10300”的任务(见下文)。但是,如何从groupName、groupDescription等获取文本?想要检索“卡内尔-布朗”等等。在我描述这个问题时,我不确定是否正确使用了“元素”和“属性” <groupInformation groupID="10300" groupName="Carnell - Brown" groupDescript

这个XPath表达式 //groups/groupInformation/@groupID[包含(,'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." />

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

而不是回答什么

我建议,

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

  • 它更简洁
  • @groupID
    为10300999或9991030时,可以避免错误匹配
太复杂(而且是错误的-认为像“包含3”这样的误报)。使用
//groupInformation[@groupID='10300']/@groupName
//groups/groupInformation[@groupID='10300']/@groupName