views:

48

answers:

2

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.

A: 

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
+1  A: 

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
Very nice didnt know that
almog.ori
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
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