Is there any way to map custom processing instruction <?code MySimpleCode?>
to a CLR type?
For example – source:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<?code MySimpleCode?>
</root>
Destination
[XmlRoot(ElementName = "root")]
public class Root
{
[XmlElement(???)]
public TYPE??? Code { get; set; }
}
2
For working with XML some find more useful using XDocument
from System.Xml.Linq namespace.
Assuming that you will provide correctly structured XML (not the exactly as in provided example), you could use below code:
var raw = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<root>
<code MySimpleCode=""""></code>
</root>";
var xDoc = XDocument.Parse(raw);
var codeNode = xDoc.Descendants("root").Descendants("code").First();
var mySimpleCode = codeNode.Attribute("MySimpleCode").Value;
1