locked
Linq to XML query set Namespace RRS feed

  • Question

  • User-943250815 posted

    I know is there a way, in Expression bellow to mention NameSpace, but I'm not finding any doc about this particular notation. There was many docs some years ago

    Dim XDoc as XDocument = XDocument.Parse(MyStringXML)
    Dim MyNode = (From p in XDoc.<main>.<state>.<city> select p.<name>). FirstOrDefault

    How can I set Namespace?
    I do not want use Element, ChildElement as actual docs suggests

    Wednesday, January 30, 2019 10:57 PM

All replies

  • User-943250815 posted

    Case Closed, found it
    Have to set Global Namespace using Import like

    Imports <xmlns:xy="http://mymanespace.xxx.zz">

    Then on Linq use

    Dim MyNode = (From p in XDoc.<xy:main>.<xy:state>.<xy:city> select p.<xy:name>).FirstOrDefault

    This is for VB code, don´t think such feature is available on C#

    Wednesday, January 30, 2019 11:40 PM