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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jazzygirl
    New Member
    • Jun 2008
    • 1

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

    I'm fairly new to vb.net (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.XmlTextWrit er, 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.XmlDataDocu ment) As Integer
    Dim ioRootNode As Xml.XmlNode
    Dim ioSubNode As Xml.XmlNode
    Dim ioDataNode As Xml.XmlNode
    Dim ioObject As New MyProject.MyObj ect

    ioObject = xmlObject

    ' ------------- Dataset Root Node -------------------------------------
    ioRootNode = ioXmlDoc.Create Node(Xml.XmlNod eType.Element, "MyDataSet" , "")
    ioXmlDoc.Append Child(ioRootNod e)

    ' ------------- Header Node -------------------------------------
    ioSubNode = ioXmlDoc.Create Node(Xml.XmlNod eType.Element, "Header", "")
    ioRootNode.Appe ndChild(ioSubNo de)

    ' ------------- Data Elements -------------------------------------
    ioDataNode = ioXmlDoc.Create Node(Xml.XmlNod eType.Element, "D01", "")
    ioDataNode.Inne rText = ioObject.D01
    ioSubNode.Appen dChild(ioDataNo de)

    ioDataNode = ioXmlDoc.Create Node(Xml.XmlNod eType.Element, "D02", "") ioDataNode.Attr ibutes.Append(i oXmlDoc.CreateA ttribute("xsi:n il", IIf(ioObject.D0 2 = "", "true",
    ioObject.D02)))
    ioSubNode.Appen dChild(ioDataNo de)

    ~~~~~~~~~~~~~~~

    Dim ioWriter As New Xml.XmlTextWrit er(cPath & vFileName, System.Text.ASC IIEncoding.ASCI I)

    ' Write XML document object to file
    ioWriter.Format ting = Xml.Formatting. Indented
    ioWriter.WriteS tartDocument()
    xmlDoc.WriteCon tentTo(ioWriter )
    ioWriter.Close( )

    ~~~~~~~~~~~~~~~
Working...