XPath:获取元素类型 [英] XPath: get element type

查看:30
本文介绍了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.

这篇关于XPath:获取元素类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆