0

I'm trying to deserialize an item from XML value but I faced with an issue when some element has : value.

My XML is like this:

Actually, I don't have any namespace on that and it comes from an internal library that I don't have access to that.

<item>
    <dc:author>Value</dc:author>
</item>

My serialization part is:

XmlSerializer serializer = new XmlSerializer(typeof(Model));

using (StringReader reader = new StringReader(value))
{
     var data = (Model)serializer.Deserialize(reader);
}

And the model class is here:

[XmlRoot("item")]
public class Model
{
    [XmlElement(ElementName = "dc:author")]
    public string Author { get; set; }
}

I couldn't deserialize the data for the Author element.

What should I do when I have the : in xml value?

9
  • Also check stackoverflow.com/questions/34331860/… Commented Dec 29, 2020 at 20:27
  • @Progman Thanks for sharing the links, I tried those but It doesn't work because I don't have namespace in my Author element. I tried like this [XmlElement(ElementName = "author", Namespace = "")] public string Author { get; set; } Commented Dec 29, 2020 at 20:37
  • @Progman Actually, I don't have any other section in this XML, It just an item section. Commented Dec 29, 2020 at 20:41
  • Where is the XML coming from and where is the "dc" coming from? That is part of an XML namespace prefix, but there is no namespace defined in your shown XML. Please edit your question to include the complete XML content you have and where it comes from. Commented Dec 29, 2020 at 20:43
  • @Progman Thanks, It comes from an Internal library that I don't have access to that and It just return an item without any namespace, right! I couldn't right the good question. Commented Dec 29, 2020 at 20:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.