How to insert block of actions in XML Literals before inserting new tag

28 views Asked by At

Help me please to understand how possible to insert inside XML Literals in VB.NET block of some actions like this: iCol = iCol + 1 iTMP = iTmp + iCol (for example in Loop i need to increase some variable before insertinf New Tag )

Dim objDoc As XDocument = <?xml version="1.0" encoding="utf-8" standalone="no"?>
. . .
<%= From i In Enumerable.Range(3, LastRow)
Where UCase(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet.Range("Y" + CStr(i)).Value) = "Y" Select
iCol = iCol + 1
iTMP = iTmp + iCol
<TagWithData>Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet.Range("Y" + CStr(iTMP)).Value</TagWithData>
. . .
1

There are 1 answers

0
FloatingKiwi On

XmlLiterals are designed for binding data into the XDocument. If you have something more complicated you wish to do then try declaring an anonymous function and binding that instead.

    Dim i As Integer = 0

    Dim myFunc = Function()
                     i += 1
                     Return i
                 End Function

    Dim doc = <xml>
                  <%= myFunc() %>
              </xml>

This has the benefit of removing more complicated logic out of the document.