locked
read xml that have namespace RRS feed

  • Question

  • User-81382370 posted

    Hi

    I have a xml file that use a namespace and therefore all the elements look something like this... <bb0:Book>Tuesdays with morrie</bb0:Book>

    How do I read that element value when it use a namespace?

    Tuesday, January 21, 2014 10:24 AM

All replies

  • User-760709272 posted

    You have to use the XmlNamespaceManager

    http://support.microsoft.com/kb/318545

    If you google you might find better examples.

    Tuesday, January 21, 2014 10:35 AM
  • User1508394307 posted

    You would meed to add namespace like this

    //Instantiate an XmlNamespaceManager object.
    System.Xml.XmlNamespaceManager xmlnsManager = new System.Xml.XmlNamespaceManager(xmldoc.NameTable);

    //Add the namespaces used in books.xml to the XmlNamespaceManager.
    xmlnsManager.AddNamespace("bb0", "urn:Books");

    See here complete example http://support.microsoft.com/kb/318545/en 

    Tuesday, January 21, 2014 10:38 AM