xpath following-sibling - null return looks for object reference?

K

Kathy Burke

I'm providing the following syntax in hopes someone could tell me why I
get an object reference error on the second one. The first one works,
using an xmlDocument, the second one immediately follows and uses the
same xmlDocument. It works if the result is not Nothing. I've used
similar xpath expressions (but never with the following-sibling
reference) and the If Nothing works ok. Spent hours on this, but I need
another set of eyes and a better brain! The varStation is correct when I
check with debug. Thanks. Kathy

Dim xDoc As New XmlDocument()
xDoc.LoadXml(varWF)

'get previous station

Dim n2 As XmlElement = xDoc.SelectSingleNode("//Station[@name='" &
varStation & "']/preceding-sibling::Station[1]")

Dim prevStation As String = n2.Attributes.GetNamedItem("name").Value

'get next station name

Dim n14 As XmlElement = xDoc.SelectSingleNode("//Station[@name='" &
varStation & "']/following-sibling::Station[position()=1]")

If n14 Is Nothing Then 'ERRORS HERE - OBJECT REFERENCE
Session("NextStation") = "End of Assembly"
Else
Session("NextStation") = n14.Attributes.GetNamedItem("name").Value
End If

MY XML string (varWF):


<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="WI_Workflow.xsl"?>
<WorkFlow>

<Assembly number="865-7446-03-BA" customer="SMITH" wo="123456"
qty="3" line="07">

<Station name="Label">
<WI order="1"
title="Apply Labels"
doc="10-ME40-865-7446-03-LB01-B.xml">
</WI>
</Station>

<Station name="Station1">
<WI order="1"
title="Work Instruction Test One"
doc="KB_TEST_WI1.xml">
</WI>
<WI order="2"
title="Work Instruction Test Two"
doc="KB_TEST_WI2.xml"
program="7446BRBC">
</WI>
</Station>

<Station name="Station2">
<WI order="1"
title="Work Instruction Test Three"
doc="KB_TEST_WI3.xml">
</WI>
</Station>

</Assembly>
</WorkFlow>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top