XDocument.Element returns null when parsing an xml string

后端 未结 4 2031
悲哀的现实
悲哀的现实 2021-01-18 09:43

I have this xml string:



        
4条回答
  •  离开以前
    2021-01-18 10:29

    Get the namespace somehow, like

    XNameSpace a = doc.Root.GetDefaultNamespace();

    or, probably better:

    XNameSpace a = doc.Root.GetNamespaceOfPrefix("a");
    

    and then use it in your queries:

    // to get 
    XElement f = doc.Element(a + "feed");
    

    You can also set the namespace from a literal string, but then avoid var.

提交回复
热议问题