Parse XDocument without having to keep specifying the default namespace

前端 未结 5 1704
北荒
北荒 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:12

    The theory is that the meaning of the document is not affected by the user's choice of namespace prefixes. So long as the data is in the namespace http://www.secretsonline.gov.uk/secrets, it doesn't matter whether the author chooses to use the prefix "s", "secrets", "_x.cafe.babe", or the "null" prefix (that is, making it the default namespace). Your application shouldn't care: it's only the URI that matters. That's why your application has to specify the URI.

提交回复
热议问题