我正在使用 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 不起作用
发布评论