Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate XML using Linq to XML and arrays
    primarykey
    data
    text
    <p>I am using Linq To XML to create XML that is sent to a third party. I am having difficulty understanding how to create the XML using Linq when part of information I want to send in the XML will be dynamic.</p> <p>The dynamic part of the XML is held as a string[,] array. This multi dimensional array holds 2 values.</p> <p>I can 'build' the dynamic XML up using a stringbuilder and store the values that were in the array into a string variable but when I try to include this variable into Linq the variable is HTMLEncoded rather than included as proper XML.</p> <p>How would I go about adding in my dynamically built string to the XML being built up by Linq?</p> <p>For Example:</p> <pre><code>//string below contains values passed into my class </code></pre> <p>string[,] AccessoriesSelected;</p> <pre><code>//I loop through the above array and build up my 'Tag' and store in string called AccessoriesXML //simple linq to xml example with my AccessoriesXML value passed into it XDocument RequestDoc = new XDocument( new XElement("MainTag", new XAttribute("Innervalue", "2") ), AccessoriesXML); </code></pre> <p>'Tag' is an optional extra, it might appear in my XML multiple times or it might not - it's dependant on a user checking some checkboxes.</p> <p>Right now when I run my code I see this:</p> <pre><code>&lt;MainTag&gt; blah blah &lt;/MainTag&gt; &amp;lt ;Tag&amp;gt ;&amp;lt ;InnerTag&amp;gt ; option1="valuefromarray0" option2="valuefromarray1" /&amp;gt ;&amp;lt ;Tag/&amp;gt ; </code></pre> <p>I want to return something this:</p> <pre><code>&lt;MainTag&gt; blah blah &lt;/MainTag&gt; &lt;Tag&gt;&lt;InnerTag option1="valuefromarray0" option2="valuefromarray1" /&gt;&lt;/Tag&gt; &lt;Tag&gt;&lt;InnerTag option1="valuefromarray0" option2="valuefromarray1" /&gt;&lt;/Tag&gt; </code></pre> <p>Any thoughts or suggestions? I can get this working using XmlDocument but I would like to get this working with Linq if it is possible.</p> <p>Thanks for your help, Rich</p>
    singulars
    1. This table or related slice is empty.
    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. 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