473,566 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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( )

~~~~~~~~~~~~~~~
Jun 2 '08 #1
0 1803

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

Similar topics

0
1896
by: Stefan Prange | last post by:
Hi everyone, I have a little problem here and wasn't able to find a proper solution by searching the web. So this newsgroups is my last resort ;-) I have an xml-schema definition of an element which reads: <xsd:element name="DoubleValue" type="xsd:double" nillable="true"/> In my instance document I have the following element:
0
3508
by: John Jenkins | last post by:
Hi, can someone tell me why the following scneario occurs. With the nillable attribute set to true on an element that has min occurs set to zero, I generate a class. As expected this adds the IsNullable=true attribute <xs:element name="SSN" type="xs:string" minOccurs="0" nillable="true"/> /// <remarks/>
0
1225
by: Greg | last post by:
I'm writing a program which uses the ImportNode function of an XMLDataDocument. This works fine for elements which may appear once at most; however, for elements which may appear multiple times, it inserts 'xsi:nil="true"' for each of those elements, which is a violation of my schema (and logic). (The code below is for cataloging...
0
5600
by: info | last post by:
Dear all, is the first time that I use SOAP, and i must say that i'm having several problems. this is SOAP message that expects the server =================XML EXPECTED FROM THE SERVER================ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"...
0
1591
by: Bakunin | last post by:
Hi, I have a brief question regarding the .net framework renders class definitions of schemas to wsdl descritions. I have observed the following: 1. I have a schema with a mandatory field (in this example a string) in my schema. 2. When I convert this to a class (using xsd.exe) all is well. There is nothing in the code that is created to...
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.