Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Nillable Catch22?

39 views
Skip to first unread message

FrankS

unread,
Aug 30, 2004, 9:11:03 PM8/30/04
to
Using SP1/VB.net and a template created from schema with optional date field
as nillable i.e.:

<xsd:element name="OptionalDate" nillable="true" type="xsd:xsd:dateTime" />


If the fist record comes from the DB as NOT null and we want to use the node
we remove nil attribute:

If de.getAttribute("xsi:nil") Then de.removeAttribute("xsi:nil") End if

and populate the node. No problemo.

However, from then on the field becomes required. ( * Only date and time
allowed). This is a problem since this is an optional field I do not want to
use it in every record.

So....

If I set nillable = true in the XSD the field becomes required (after the
attribute removed)

OR

If I leave out attribute it is always required.

Is this right? Please tell me what I have overlooked.

Thanks,

Frank

Greg Collins [MVP]

unread,
Aug 31, 2004, 2:00:43 PM8/31/04
to
When ever you have a value in the field, the nillable attribute must be removed. Then when you clear the value of the field, you must set the nillable attribute on the element.

This is true for date, boolean, numeric and other non-string data types.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com

"FrankS" <Fra...@discussions.microsoft.com> wrote in message news:561E7084-9D70-4F6D...@microsoft.com...

FrankS

unread,
Aug 31, 2004, 2:57:14 PM8/31/04
to
Thanks Greg,
I tried this:
Public Sub SetNil(ByVal de As IXMLDOMElement, ByVal blnNillable As
Boolean)...

If blnNillable Then
de.setAttribute("xsi:nil", True)
Else
de.removeAttribute("xsi:nil")
End If
it removes it just fine but gets an error on the set: The attribute 'nil' on
the element xxx is not defined in the DTD/schema. The set attribute is not
working.

Please give example? Thanks
Frank

FrankS

unread,
Sep 1, 2004, 9:19:08 AM9/1/04
to
I tried set attribute to true and false and that di not work. I also tried
this:
Public Sub SetNil(ByVal de As IXMLDOMElement, ByVal blnNillable As
Boolean)...
Try
If blnNillable Then
Dim xa As IXMLDOMAttribute
xa = de.ownerDocument.createAttribute("xsi:nil")
xa.value = "True"
de.setAttributeNode(xa)
Else
de.removeAttribute("xsi:nil")
End If
Catch ex As Exception
thisXDoc.UI.Alert(ex.Message)
End Try
However the field is still required. Please post something that is workable.

Thanks,

FrankS

unread,
Sep 1, 2004, 2:49:13 PM9/1/04
to
Greg, This falls under the *you-have-got-to-kidding* category!! LOL I fought
this and fought this only to find out that the text value *True* is <>
*true*. Duh!
Thanks for responses.
This was the fix:
--------------------------------

Try
If blnNillable Then
Dim xa As IXMLDOMNode
xa = de.ownerDocument.createNode(2, "xsi:nil",
"http://www.w3.org/2001/XMLSchema-instance")
xa.text = "true" 'must be lowercase


de.setAttributeNode(xa)
Else
de.removeAttribute("xsi:nil")
End If
Catch ex As Exception
thisXDoc.UI.Alert(ex.Message)
End Try

Greg Collins [MVP]

unread,
Sep 1, 2004, 3:28:40 PM9/1/04
to
Glad you got it working.

Yes the values are case-sensitive. But this isn't always a commonly known issue.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com

"FrankS" <Fra...@discussions.microsoft.com> wrote in message news:2C5BBB80-0238-4A44...@microsoft.com...

0 new messages