0

I have an XDocument which contains embedded values:

<name>
  <firstname><%= firstname %></firstname>
  <lastname><%= lastname %></lastname>
</name>

when this appears in the body of my code, it works entirely as expected

e.g.

Dim strfirstname = "John"
dim strastname = "Smith"

Dim NameXML = <name>
                <firstname><%= strfirstname %></firstname>
                <lastname><%= strlastname %></lastname>
              </name>

Debug.Print(NameXML.ToString)

produces

<name>
 <firstname><John></firstname>
 <lastname><Smith></lastname>
</name>

However, I would like to save my XDocument to an .xml file (it is a bit longer than this example), load it at run-time and produce the same result as above.

e.g.

Dim NameXML = XDocument.Load("/names.xml")
Debug.Print(NameXML.ToString)

This produces an error:

"Name cannot begin with the '%' character"

I have also tried loading the XDocument as a string:

 Dim strNames = My.Computer.FileSystem.ReadAllText("\names.xml")
 Dim NameXML = XDocument.Parse(template)

but I get the same error.

Is it possible to load the XDocument, complete with all embedded values? Or must it remain in my code to work?

Thanks!

Alex Webster
  • 707
  • 1
  • 6
  • 21
  • I'd say, that's not possible. When you write `<%= .. =>` in your vb.net code it's translated by compiler into proper methods, to generate the `XDocument`, while `XDocument.Load()/Parse()` methods just initialize `XDocument` from given source. It's a huge difference. – MarcinJuraszek Aug 15 '13 at 21:30
  • Thanks Marcin. I suppose that the next best thing would be a simple string.replace method - which seems kind of agricultural, but will work... – Alex Webster Aug 15 '13 at 22:12
  • Consider using Razor to do what you're trying to do. http://stackoverflow.com/questions/3628895/is-it-possible-to-use-razor-view-engine-outside-asp-net – CoderDennis Oct 31 '13 at 15:04

0 Answers0