How can I get rid of the namespace prefix from XElement like this (C#)?



I have got an xml string like this, and I am trying to deserialize it to an object with class Credentials. But the namespace prefix is stopping me.


The Credentials class itself doesn't have any XmlRoot attribute to set namespace. But some class which contains a Credentials property does. And the "ds" prefix below is from the container's serialized xml.


The container's xml is like this:



<ds:DataSource xmlns:ds="urn:My-Namespace">
<ds:Credentials>
<ds:UserName>foo</ds:UserName>
<ds:Domain>bar</ds:Domain>
</ds:Credentials>
</ds:DataSource>"


Then when I get the element "Credentials" from the containter element, it returns this:



<ds:Credentials xmlns:ds="urn:My-Namespace">
<ds:UserName>foo</ds:UserName>
<ds:Domain>bar</ds:Domain>
</ds:Credentials>


I can't deserialize this to a correct Credentials object. Is that possible to remove it? I have tried How to remove namespace prefix. (C#), the element still got a default namespace there.



<Credentials xmlns="urn:My-Namespace">
<UserName>foo</UserName>
<Domain>bar</Domain>
</Credentials>

No comments:

Post a Comment