Expression in XML Literal Processing Instruction?
-
Tuesday, October 09, 2012 2:51 AM
Why doesn't the <?qbxml...?> line work? Is there a way to embed an expression in a processing instruction? If I remove the <?qbxml...?> line, then it produces valid xml. With the line it won't compile.
Dim qbXmlRq2 As XDocument = <?xml version="1.0"?> <?qbxml version=<%= QBXMLVer %>?> <QBXML> <QBXMLMsgsRq onError="stopOnError"> <<%= transType & "QueryRq" %> requestID=<%= ReferenceNumber %>> <RefNumber><%= ReferenceNumber %></RefNumber> <IncludeLineItems>1</IncludeLineItems> <OwnerID>0</OwnerID> </> </QBXMLMsgsRq> </QBXML>
All Replies
-
Tuesday, October 09, 2012 3:43 PM
According to http://msdn.microsoft.com/en-us/library/bb385055.aspx you can't use expressions in a VB.NET processing instruction literal.
Processing instructions can take any data, while they are often used to contain pseudo attributes in 'name="value"' syntax that is not the only allowed syntax.
If you want to construct a processing instruction data dynamically then I don't think you can use a literal, you will need to use code as in
Dim QBXMLVer As String = "test-1.0" Dim doc As XDocument = <?xml version="1.0"?> <Root> <Foo>Bar</Foo> </Root> doc.AddFirst(New XProcessingInstruction("qbxml", String.Format("version=""{0}""", QBXMLVer)))that creates
<?qbxml version="test-1.0"?> <Root> <Foo>Bar</Foo> </Root>
MVP Data Platform Development My blog

