XPath:获取元素类型

问题描述:

这是一个 XPath 查询,它将打印文件中每个元素的完整路径

This is an XPath query which would print full path of every element in the file

for $boy in //*
return string-join(($boy/ancestor-or-self::*/name()), "::")

我如何获得元素的类型(我首先需要知道原始类型:xs:integerxs:string 等)?

How do I get the element's type as well (I need to know primitive types foremost: xs:integer, xs:string, etc)?

没有确定元素类型的函数.当您使用 flwor 表达式时,我猜您的 XPath 处理器支持 XPath 2.0:然后您可以使用 instance of 来确定类型,例如.

There is no function to determine an element's type. As you're using flwor expressions, I guess your XPath processor supports XPath 2.0: then you can use instance of to determine the type, eg.

  • xs:string 的foo"实例
  • 1 个 xs:integer 实例
  • ///* element()的实例*

您可以使用 if/else-chain 来确定类型(该示例使用 XQuery,在 XPath 中您不能定义函数),但我现在无法真正想出一个 XPath 应用程序示例.

You could use use an if/else-chain to determine the type (the example uses XQuery, in XPath you cannot define functions), but I cannot really come up with an XPath application example right now.