By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,411 Members | 1,037 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,411 IT Pros & Developers. It's quick & easy.

How to add xsi:nil="true" to an XML document node using

P: 1
I'm fairly new to (self-taught and realizing how much I DON'T know). I need to create an XML output file (I'm quite ignorant in this area as well!). I used an XMLDataDocument and Xml.XmlTextWriter, creating each element node since the agency I'm sending the file to is very specific about the format.

How do I specify an element/node/attribute (whatever) to output xsi:nil="true"?

Desired Output:
<D02 xsi:nil="true" />

Current Output:
<D02 xsi:nil="" xmlns:xsi="true" />

Visual Basic Code:
Function Create_XML_File(ByVal xmlObject As MyObject, _
ByRef ioXmlDoc As Xml.XmlDataDocument) As Integer
Dim ioRootNode As Xml.XmlNode
Dim ioSubNode As Xml.XmlNode
Dim ioDataNode As Xml.XmlNode
Dim ioObject As New MyProject.MyObject

ioObject = xmlObject

' ------------- Dataset Root Node -------------------------------------
ioRootNode = ioXmlDoc.CreateNode(Xml.XmlNodeType.Element, "MyDataSet", "")

' ------------- Header Node -------------------------------------
ioSubNode = ioXmlDoc.CreateNode(Xml.XmlNodeType.Element, "Header", "")

' ------------- Data Elements -------------------------------------
ioDataNode = ioXmlDoc.CreateNode(Xml.XmlNodeType.Element, "D01", "")
ioDataNode.InnerText = ioObject.D01

ioDataNode = ioXmlDoc.CreateNode(Xml.XmlNodeType.Element, "D02", "") ioDataNode.Attributes.Append(ioXmlDoc.CreateAttrib ute("xsi:nil", IIf(ioObject.D02 = "", "true",


Dim ioWriter As New Xml.XmlTextWriter(cPath & vFileName, System.Text.ASCIIEncoding.ASCII)

' Write XML document object to file
ioWriter.Formatting = Xml.Formatting.Indented

Jun 2 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.