Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Parsing XML

Parsing XML

Scheduled Pinned Locked Moved C#
helpcsharpdatabasexmlcom
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Neel07
    wrote on last edited by
    #1

    I am trying to drill down a xml file having schema reference in c# .NET and while processing have added namespace using XmlNamespaceManager but it still gives error "Namespace Manager or XsltContext needed. This query has a prefix, variable,or user-defined function." Following is the code snippet -----------------code snippet----------------------------------------- XmlDocument objDoc = new XmlDocument(); XmlNode objRoot; objDoc.Load("C:\\abc.xml"); XmlNamespaceManager objXmlNS = new XmlNamespaceManager(objDoc.NameTable); objXmlNS.AddNamespace("xmlns:OrigoNS","http://www.origoservices.com"); objRoot=objDoc.DocumentElement; string MsgID=objRoot.SelectSingleNode("//OrigoNS:message_id").InnerText ------------------- abc.xml ---------------------------------- 2005-07-25T09:55:30342C3E5F-xxx4-4073-Byyy-C543973AA2960abc Valuation Requestv1.0synchronousxyzabctest ----------------------------------------------------------------- Would appreciate your help if you have got any clue for this problem Thanks Share knowledge to enhance your learning

    L 1 Reply Last reply
    0
    • N Neel07

      I am trying to drill down a xml file having schema reference in c# .NET and while processing have added namespace using XmlNamespaceManager but it still gives error "Namespace Manager or XsltContext needed. This query has a prefix, variable,or user-defined function." Following is the code snippet -----------------code snippet----------------------------------------- XmlDocument objDoc = new XmlDocument(); XmlNode objRoot; objDoc.Load("C:\\abc.xml"); XmlNamespaceManager objXmlNS = new XmlNamespaceManager(objDoc.NameTable); objXmlNS.AddNamespace("xmlns:OrigoNS","http://www.origoservices.com"); objRoot=objDoc.DocumentElement; string MsgID=objRoot.SelectSingleNode("//OrigoNS:message_id").InnerText ------------------- abc.xml ---------------------------------- 2005-07-25T09:55:30342C3E5F-xxx4-4073-Byyy-C543973AA2960abc Valuation Requestv1.0synchronousxyzabctest ----------------------------------------------------------------- Would appreciate your help if you have got any clue for this problem Thanks Share knowledge to enhance your learning

      L Offline
      L Offline
      Lars Niedziolka
      wrote on last edited by
      #2

      Hi Neel07, The Problem is the line: objXmlNS.AddNamespace("xmlns:OrigoNS","http://www.origoservices.com"); You register the namespace uri http://www.origoservices.com with the prefix xmlns:OrigoNS. But you request uses the prefix OrigoNS only. Simple use following line: objXmlNS.AddNamespace("OrigoNS","www.origoservices.com"); Good Luck! Niedzi PS: If you use xml code in your message, please use the Symbols < and > of the formating line (above the smilies) for the angle brackets. Or write simple < and > for < and >.

      N 1 Reply Last reply
      0
      • L Lars Niedziolka

        Hi Neel07, The Problem is the line: objXmlNS.AddNamespace("xmlns:OrigoNS","http://www.origoservices.com"); You register the namespace uri http://www.origoservices.com with the prefix xmlns:OrigoNS. But you request uses the prefix OrigoNS only. Simple use following line: objXmlNS.AddNamespace("OrigoNS","www.origoservices.com"); Good Luck! Niedzi PS: If you use xml code in your message, please use the Symbols < and > of the formating line (above the smilies) for the angle brackets. Or write simple < and > for < and >.

        N Offline
        N Offline
        Neel07
        wrote on last edited by
        #3

        Thanks a lot I have found the solution and you are right we should mention only "OrigoNS" as namespace prefix. Also it should call the 1st overloaded method of SelectSingleNode passing the XmlNamespaceManager object in the 2nd parameter. Corrected code XmlDocument objXmlDoc = new XmlDocument(); objXmlDoc.Load("C:\\abc.xml"); objRoot=objXmlDoc.DocumentElement; XmlNamespaceManager objXmlNS = new XmlNamespaceManager(objXmlDoc.NameTable); objXmlNS.AddNamespace("OrigoNS","http://www.origoservices.com"); XmlNode objRoot; string MsgID=objRoot.SelectSingleNode("//OrigoNS:message_id",objXmlNS).InnerText; Share knowledge to enhance your learning

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups