EDN Admin
Well-known member
Hello,
Im trying to serialize an object using Linq to XML (Id prefer to use this over XML serialization due to other project requirements). The object has a property representing a collection; the below code sample represents what Im trying to do, but
it doesnt like my syntax when I try to add the foreach:
<div style="color:Black;background-color:White; <pre>
<span style="color:Green; // item is a user defined type passed to the method with a property AssociatedSubItems which is a List<SubItem>.
<span style="color:Blue; var mappings =
<span style="color:Blue; new XElement(_xmlNamespace + <span style="color:#A31515; "nodeName",
<span style="color:Blue; new XAttribute(<span style="color:#A31515; "id", item.id),
<span style="color:Blue; foreach (SubItem sItem <span style="color:Blue; in item.AssociatedSubItems)
{
<span style="color:Blue; new XElement(_xmlNamespace + <span style="color:#A31515; "sItem",...
}
[/code]
I assume there must be a way to do this in Linq to XML, but I wasnt able to find any examples online. Thanks for any help/suggestions.
CF
View the full article
Im trying to serialize an object using Linq to XML (Id prefer to use this over XML serialization due to other project requirements). The object has a property representing a collection; the below code sample represents what Im trying to do, but
it doesnt like my syntax when I try to add the foreach:
<div style="color:Black;background-color:White; <pre>
<span style="color:Green; // item is a user defined type passed to the method with a property AssociatedSubItems which is a List<SubItem>.
<span style="color:Blue; var mappings =
<span style="color:Blue; new XElement(_xmlNamespace + <span style="color:#A31515; "nodeName",
<span style="color:Blue; new XAttribute(<span style="color:#A31515; "id", item.id),
<span style="color:Blue; foreach (SubItem sItem <span style="color:Blue; in item.AssociatedSubItems)
{
<span style="color:Blue; new XElement(_xmlNamespace + <span style="color:#A31515; "sItem",...
}
[/code]
I assume there must be a way to do this in Linq to XML, but I wasnt able to find any examples online. Thanks for any help/suggestions.
CF
View the full article