Prefix ‘z’ is not defined error in SharePoint

Prefix ‘z’ is not defined error in SharePoint

November 24th, 2006 // 9:11 pm @

If you are trying to programmatically add items to a sharepoint list, using the web services, you might encounter this error while analysing the return value. I was adding entries to the site directory and on adding an entry, you get a XML result set back. Something similar to what is presented below: ( I have omitted bits which are not relevant )


<Results xmlns=”http://schemas.microsoft.com/sharepoint/soap/”>
<Result ID=”2,New”>
<ErrorCode>0×00000000 <ID />
<z:row ows_ID=”20″ … xmlns:z=”#RowsetSchema” />
</Result>
</Results>


Now, the problem is when you try to parse this, you will encounter the error “Prefix ‘z’ is not defined”. This happens because at this stage, the XML parser does not have any idea what the z in the z:row stands for. The solution I used, was to create a NamespaceManager and add the namespace of z to it manually. The following code will parse the resultset we have.



SiteDirectoryWS.Lists sd = new SiteDirectoryWS.Lists;


// form the xml to add an entry in the Sites list.


XmlNode returnNode = sd.UpdateListItems(“Sites”, insertListElement);


XmlDocument xmlDoc = new XmlDocument;
xmlDoc.LoadXml(returnNode.OuterXml);


XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsmgr.AddNamespace(“z”, “#RowsetSchema”);
nsmgr.AddNamespace(“rs”, “urn:schemas-microsoft-com:rowset”);


XmlNode elem = returnNode.SelectSingleNode(“.//z:row”, nsmgr);


If (elem != null)
retID = elem.Attributes(“ows_ID”).Value;


Category : SharePoint

5 Comments → “Prefix ‘z’ is not defined error in SharePoint”


  1. http://

    5 years ago

    nice work Amar! you really saved my bacon!


  2. Rajesh

    1 year ago

    Thank You Amar, I wanted to read my GetListItems first row and your tip really helped me!!


  3. Natasha

    3 months ago

    You Save My Life!… Thank You!


  4. Natasha

    3 months ago

    You Saved My Life!… Thank You!


  5. Amar

    3 months ago

    Good to know that helped.


Leave a Reply

Latest Posts

Testimonials

"Amar clearly has a thorough knowledge of Sharepoint, this knowledge, coupled with his professionalism and dedication made him a tremendous asset to the project. He was the key contributor to the later stages of the project delivery effort (the really difficult bit, long hours and hard work that puts huge demands on people), and I can state categorically that without his focussed dedication and hard work we would not have been able to meet the timescales imposed upon the project."

Tim Ellis , Sharepoint Project Manager , Royal Bank of Scotland

Subscribe Now