1

so i have some inline XML

Dim x As XElement = _
    <parent>
        <child></child>                    
    </parent>

what I want to do is get some variables that have been set into that xml

Dim v as string = "Blah"
Dim x As XElement = _
    <parent>
        <child>{v}</child>                    
    </parent>

Is this possible? I am aware that I could make the whole thing one giant string and concatenate, or string.format. But I want to know if this method is possible.

Russ Bradberry
  • 10,705
  • 17
  • 69
  • 85

2 Answers2

2

so, just as a guess, i tried using a <%= tag and it seems to have worked:

Dim v as string = "Blah"
Dim x As XElement = _
    <parent>
        <child><%= v %></child>                    
    </parent>
Russ Bradberry
  • 10,705
  • 17
  • 69
  • 85
  • That syntax is meant to permit you to use LINQ expressions in there as well. See example at http://blogs.msdn.com/stcheng/archive/2008/03/05/asp-net-use-linq-to-xml-to-construct-xml-document-from-database-records.aspx. – John Saunders Jul 17 '09 at 00:24
  • yeah, i had no idea about this. its very convenient, this way I don't have to go through and change every line of xml to accomplish what I need. – Russ Bradberry Jul 17 '09 at 16:10
0

The System.Xml.Linq namespace is very flexable, so yes you can one way would be

Dim x As XElement = <test><One></One></test>
    x.FirstNode.ReplaceWith(<test2></test2>)

Output is <test><test2></test2></test>
almog.ori
  • 7,839
  • 1
  • 35
  • 49