Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing strings in XML Literals
    primarykey
    data
    text
    <p>I'm a C# developer who's fumbling in the first VB code he's written since VB6, so if I am asking a rather obvious question, please forgive me.</p> <p>I decided to experiment with XML Literals to generate some XML code for me, instead of using XMLDocument</p> <p>I have 2 questions, the second regarding a workaround due to my inability to figure out the first.</p> <p>1: Ideal solution</p> <p>I have a Dictionary of ElementName, ElementValue whose KeyValue pairs I was looping over in the hope of generating the values dynamically, but the following syntax dies a horrible death</p> <pre><code>Dim xConnections As XElement For Each connection As Connection In connections.AsList For Each kvp As KeyValuePair(Of String, String) In connection.DecompiledElements xConnections = &lt;Connections&gt; &lt;&lt;%= kvp.Key %&gt;&gt;&lt;%= kvp.Value %&gt;&lt;\&lt;%=kvp.Key %&gt;&gt; &lt;/Connections&gt; Next Next </code></pre> <p>I have vague memories of the T4 syntax (the &lt;%=%> syntax) being able to handle more complex operations (rather than direct assignment to the &lt;%= ) and a 'Response.Write' like object to write output to, but I can't remember the details.</p> <p>2: Cludgy workaround</p> <p>Instead I thought of building a StringBuilder object and assigning its .ToString to the XElement, but that also failed with a conversion error.</p> <p>I would prefer to continue using my key value pair concept in example one above, as I feel cludging together a string as in example 2 above is rather nasty, and I really should go back to using XMLDocument if instead.</p> <p>Any thoughts or assistance greatly appreciated</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. 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