开发者

Optional Fields in InfoPath; Getting the XML node with VB

I use V开发者_运维技巧B to get data through my form. I have some optional fields in my form and I have a problem with the following code:

MsgBox(myXPathNavigator.SelectSingleNode( _
  "/my:Status/my:Questions/my:Questions1", Me.NamespaceManager _
).IsNode.ToString)

When the optional field 'Questions1' is inserted into the form I get the value 'true' by the IsNode() function.

If the field it is not inserted I have an exception stating that the reference is not correct (and it is indeed true). Is there a way to verify about a node, whether it is present or not in my form?

Thanks in advance, Sun


Just don't do it in one step. SelectSingleNode() returns Nothing if the XPath was not found. You must catch that condition separately.

Dim q As XPathNavigator
Dim path as String

path = "/my:Status/my:Questions/my:Questions1"
q = myXPathNavigator.SelectSingleNode(path, Me.NamespaceManager)

If Not q Is Nothing Then
  MsgBox(q.ToString)
End If
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜