Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If all you want to do change (transform) one XML format to another XML format then I think the approach you are taking is not the most appropriate. There are other APIs in the framework that support this kind of functionality. In your case the requirement seems rather simple, so I would opt for the <a href="http://msdn.microsoft.com/en-us/library/bb387098.aspx" rel="nofollow noreferrer">Linq To Xml</a> option. The following is a quick example, which produces the desired output.</p> <pre><code>XDocument doc = XDocument.Parse(@"&lt;Properties&gt; &lt;Property name='ID'&gt;10000&lt;/Property&gt; &lt;Property name='Name'&gt; &lt;SubProperty name='FirstName'&gt;Foo&lt;/SubProperty&gt; &lt;SubProperty name='LastName'&gt;Bar&lt;/SubProperty&gt; &lt;/Property&gt; &lt;/Properties&gt;"); XElement items = new XElement("Items", from property in doc.Descendants("Property") select new XElement((string)property.Attribute("name"), // If there are no child elements (SubPropety) // get the property value property.HasElements ? null : (string)property, // Another way for checking if there are any child elements // You could also use property.HasElements like the previous statement property.Elements("SubProperty").Any() ? from subproperty in property.Elements("SubProperty") select new XElement((string)subproperty.Attribute("name"), (string)subproperty) : null) ); </code></pre> <p>A few resouces that may be of help include:</p> <p><a href="http://msdn.microsoft.com/en-us/library/bb387098.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/bb387098.aspx</a></p> <p><a href="http://msdn.microsoft.com/en-us/library/bb308960.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/bb308960.aspx</a></p> <p><a href="http://iqueryable.com/2007/08/03/TransformingXMLWithLINQToXML.aspx" rel="nofollow noreferrer">http://iqueryable.com/2007/08/03/TransformingXMLWithLINQToXML.aspx</a></p> <p><a href="http://www.codeproject.com/KB/linq/LINQtoXML.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/linq/LINQtoXML.aspx</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload