简体   繁体   English

SQL Server XML query()-缺少父节点或名称空间

[英]SQL Server XML query() - Missing parent node or namespace

We need to query concatenated tags from XML records stored in a SQL Server database by querying sub sections of XML documents. 我们需要通过查询XML文档的子部分来从存储在SQL Server数据库中的XML记录中查询串联标签。 The only tricky issue is that some of our records are missing the parent node, other don't. 唯一棘手的问题是,我们的某些记录缺少父节点,而其他记录则没有。 The other aspect is that that some records contain namespaces in the root and other don't. 另一方面是某些记录在根目录中包含名称空间,而其他则不包含。

So two things here, how can we adjust the path in the query() to ignore namespaces and query all mynode sections regardless of the namespaces. 因此,这里有两件事,我们如何调整query()的路径以忽略名称空间并查询所有mynode节,而不管名称空间如何。 And how to query all the mynode sections regardless of the presence of the root node. 以及如何查询所有mynode节,而不管根节点是否存在。

select 
    xmlCol.query('*:rootnode/*:mynode/*') 
from 
    DataTable

Any help on this would be appreciated 任何帮助,将不胜感激

Thanks 谢谢

Have a good day 祝你有美好的一天

You can use double slash (//) to find a node , independently in which parent node is belonging to.. 您可以使用双斜杠(//)独立地找到父节点所属的节点。

So i suppose that it should be something like 所以我想应该是这样的

select xmlCol.query('//mynode/*') from DataTable

but more information about your table would be helpful. 但是有关表格的更多信息会有所帮助。

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM