我正在使用SharePoint Web服务从网站检索内容类型。输出看起来像这样:
<ContentTypes ContentTypeOrder="0x010300971A94A609AC5F4390A1FF87A26CD05D" xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<ContentType Name="Issue" ID="0x010300971A94A609AC5F4390A1FF87A26CD05D"
Description="Track an issue or problem."
Scope="https://practiv1.sharepoint.com/devtest/Lists/issueTracking"
Version="0"
BestMatch="TRUE">
<XmlDocuments>
<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<FormTemplates xmlns="http://schemas.microsoft.com/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="https://practiv1.sharepoint.com/devtest/Lists/issueTracking"
Version="0">
<XmlDocuments>
<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<Display>ListForm</Display>
<Edit>ListForm</Edit>
<New>ListForm</New>
</FormTemplates>
</XmlDocument>
</XmlDocuments>
</ContentType>
我想使用xpath来检索项目。但是我使用了类似“ // ContentType”或“ / ContentTypes / ContentType”的路径,但找不到任何东西:
var listService = new ListWebService.Lists();
listService.Url = "xxx.sharepoint.com/xxx/_vti_bin/Lists.asmx";
var contents = listService.GetListContentTypes("issueTracking", "0x01");
有人可以帮我解决我的xpath问题吗?
在处理具有默认名称空间(xmlns="..."
)的XML时,这是一个常见问题。声明前缀的节点及其所有后代(如果没有明确指定的话)将在默认名称空间中考虑。
您需要注册一个指向名称空间URI的前缀,并在XPath中使用该前缀,例如:
var nsManager = new XmlNamespaceManager(new NameTable());
nsManager.AddNamespace("d", "http://schemas.microsoft.com/sharepoint/soap/");
var result = contents.SelectNodes("//d:ContentType", nsManager);
//or using the other XPath : "/d:ContentTypes/d:ContentType"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句