为什么我的 xpath 不起作用

编程入门 行业动态 更新时间:2024-10-26 14:26:59
本文介绍了为什么我的 xpath 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 SharePoint 网络服务从网站检索内容类型.输出如下所示:

I am using SharePoint webservice to retrieve content type from the site. The output looks like this:

<ContentTypes ContentTypeOrder="0x010300971A94A609AC5F4390A1FF87A26CD05D" xmlns="schemas.microsoft/sharepoint/soap/"> <ContentType Name="Issue" ID="0x010300971A94A609AC5F4390A1FF87A26CD05D" Description="Track an issue or problem." Scope="practiv1.sharepoint/devtest/Lists/issueTracking" Version="0" BestMatch="TRUE"> <XmlDocuments> <XmlDocument NamespaceURI="schemas.microsoft/sharepoint/v3/contenttype/forms"> <FormTemplates xmlns="schemas.microsoft/sharepoint/v3/contenttype/forms"> <Display>ListForm</Display> <Edit>ListForm</Edit> <New>ListForm</New> </FormTemplates> </XmlDocument> </XmlDocuments> </ContentType> <ContentType Name="Folder" ID="0x01200049A00CD1A9F3944A9AE7BCCAC15B02D4" Description="Create a new folder." Scope="practiv1.sharepoint/devtest/Lists/issueTracking" Version="0"> <XmlDocuments> <XmlDocument NamespaceURI="schemas.microsoft/sharepoint/v3/contenttype/forms"> <FormTemplates xmlns="schemas.microsoft/sharepoint/v3/contenttype/forms"> <Display>ListForm</Display> <Edit>ListForm</Edit> <New>ListForm</New> </FormTemplates> </XmlDocument> </XmlDocuments> </ContentType>

我想使用 xpath 来检索项目.但是我使用了像//ContentType"或/ContentTypes/ContentType"这样的路径,我找不到任何东西:

I want to use xpath to retrieve items. But I used the path like "//ContentType" or "/ContentTypes/ContentType", I couldn't find anything :

var listService = new ListWebService.Lists(); listService.Url = "xxx.sharepoint/xxx/_vti_bin/Lists.asmx"; var contents = listService.GetListContentTypes("issueTracking", "0x01");

有人可以帮我看看我的 xpath 有什么问题吗?

Can someone help me what wrong with my xpath?

推荐答案

这是处理具有默认命名空间 (xmlns="...") 的 XML 时的常见问题.声明前缀的节点及其所有后代,如果没有明确指定,则在默认命名空间中被考虑.

This is a common problem when dealing with XML having default namespace (xmlns="..."). The node where the prefix declared and all it's descendants, if not explicitly specified otherwise, are considered in the default namespace.

您需要注册一个指向命名空间 URI 的前缀并在您的 XPath 中使用该前缀,例如:

You need to register a prefix that points to the namespace URI and use that prefix in your XPath, for example :

var nsManager = new XmlNamespaceManager(new NameTable()); nsManager.AddNamespace("d", "schemas.microsoft/sharepoint/soap/"); var result = contents.SelectNodes("//d:ContentType", nsManager); //or using the other XPath : "/d:ContentTypes/d:ContentType"

更多推荐

为什么我的 xpath 不起作用

本文发布于:2023-11-06 13:24:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563804.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   xpath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!