Parse XDocument without having to keep specifying the default namespace

前端 未结 5 1711
北荒
北荒 2021-02-13 16:51

I have some XML data (similar to the sample below) and I want to read the values in code.

Why am I forced to specify the default namespace to access each element? I woul

5条回答
  •  春和景丽
    2021-02-13 17:19

    You can use XmlTextReader.Namespaces property to disable namespaces while reading XML file.

    string filePath;
    XmlTextReader xReader = new XmlTextReader(filePath);
    xReader.Namespaces = false;
    XDocument xDoc = XDocument.Load(xReader);
    

提交回复
热议问题