![]() |
xpath following-sibling - null return looks for object reference?
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> *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
| All times are GMT. The time now is 07:08 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.