forge

XML Namespaces and Bad Exception Propigation

Two quick things …

1) If you’re trying to use XPath on XML you get back from SharePoint… don’t forget you’re going to need the XmlNamespaceManager object to use with SelectSingleNode or SelectNodes to get back what you’re looking for.  I repeatedly forget that SharePoint uses XML Namespaces extensively… and that using SelectSingleNode and SelectNodes does require namespaces in the XPath.  (Today was lesson #3.)

Help Your SharePoint User

2) Bad error handling.  You may find it interesting to note that the WebPartPages web services’ GetWebPartProperties method doesn’t seem to throw soap exceptions.  I ran into my favorite “Cannot complete…” error again.  However, it didn’t show up immediately because rather than throwing a soap exception this particular method returns the error as a comment node — rather than throwing an error.  So you’ll have to look for comments one level down from the root.  (Sidebar: It doesn’t look like this web service even works against SharePoint Portal Server areas.  At least – I keep getting an error about XML namespaces — back as a comment.)