471,599 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,599 software developers and data experts.

how do i change a value of a node?

i keep getting Object references not set to an instance of an object from
this code:

Private Sub EqBinding()
Dim x As Integer
x = 0
Do
If CStr(arlsType.Item(x)) = "Bacnet Point" Then
Dim str1, str2 As String
str1 = CStr(arlsFilePath.Item(x))
str1 = str1.Substring(0, str1.LastIndexOf("."))
str1 = str1.Remove(0, 42)
str2 = str1 + "_" + CStr(arlsBacNetType.Item(x)) + "." +
CStr(arlsInstNum.Item(x))
Dim xDoc As New Xml.XmlDocument
xDoc.Load(CStr(arlsFilePath.Item(x)))
Dim xNode As Xml.XmlNode =
xDoc.SelectSingleNode("/EquipmentObject/EquipmentPropertiesEx/EquipmentProperty[@Name='" + CStr(arlsVarName.Item(x)) + "']/Reference/@ObjectKey")
xNode.Value = str2
xDoc.Save(CStr(arlsFilePath.Item(x)))
End If
x += 1
Loop Until x = arlsVarName.Count
End Sub
#End Region

what am i missing? i just need to change the ObjectKey's node value but i
keep getting object references not set to an instance of an object

thank

Aug 7 '06 #1
7 2004


dotnetnoob wrote:
i keep getting Object references not set to an instance of an object from
Dim xDoc As New Xml.XmlDocument
xDoc.Load(CStr(arlsFilePath.Item(x)))
Dim xNode As Xml.XmlNode =
xDoc.SelectSingleNode("/EquipmentObject/EquipmentPropertiesEx/EquipmentProperty[@Name='" + CStr(arlsVarName.Item(x)) + "']/Reference/@ObjectKey")
xNode.Value = str2
On which line do you get the error, on the line above? That means that
SelectSingleNode with the XPath expression passed in has not found a
matching node and xNode is Nothing in VB.
We would need to see the XML or relevant parts of it to be able to say
why the XPath does not find a node.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 7 '06 #2
Run in a debugger. Ensure that xNode is actually finding a node. Its possible that your XPath is faulty and there is not any node that matches the particular XPath.

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Aug 7 '06 #3
the problem is on this line: xObjKey.Value = str2

I test the xpath query with Altova XMLSpy and it work perfectly getting me
to that Node and all i want is to change the value of Node ObjectKey="" to
ObjectKey= 800....(number)

but i'm keep getting: "Object reference not set to an instance of an object."

this is the xml strucutre:

<EquipmentPropertiesEx>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,16
80,32" DataType="integer" Enabled="1" Inner="0" Name="inPump1Status"
Persistent="1" Value="1">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,64
80,32" DataType="integer" Enabled="1" Inner="0" Name="inPump2Status"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,112
80,32" DataType="integer" Enabled="1" Inner="0" Name="inPump3Status"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,160
80,32" DataType="integer" Enabled="1" Inner="0" Name="inPump1Failure"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,208
80,32" DataType="integer" Enabled="1" Inner="0" Name="inPump2Failure"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,256
80,32" DataType="integer" Enabled="1" Inner="0" Name="inPump3Failure"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,304
80,32" DataType="float" Enabled="1" Inner="0" Name="inSetpoint1"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,352
80,32" DataType="float" Enabled="1" Inner="0" Name="inSetpoint2"
Persistent="1" Value="73">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,400
80,32" DataType="float" Enabled="1" Inner="0" Name="inSetpoint3"
Persistent="1" Value="69">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,448
80,32" DataType="integer" Enabled="1" Inner="0" Name="inTowerSelection"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,496
80,32" DataType="float" Enabled="1" Inner="0" Name="inTemp" Persistent="1"
Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,544
80,32" DataType="integer" Enabled="1" Inner="0" Name="inTwr1Failure"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,688
80,32" DataType="integer" Enabled="1" Inner="0" Name="inTwr2Failure"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="input" Category="" Coordinates="16,784
80,32" DataType="integer" Enabled="1" Inner="0" Name="inTwr3Failure"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,832
80,32" DataType="float" Enabled="1" Inner="0" Name="varDb1" Persistent="1"
Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,880
80,32" DataType="float" Enabled="1" Inner="0" Name="varDb2" Persistent="1"
Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,928
80,32" DataType="float" Enabled="1" Inner="0" Name="varDb3" Persistent="1"
Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,976
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeStart"
Persistent="1" Value="5">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1024
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeStart1"
Persistent="1" Value="1110820127.788">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1072
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeStart2"
Persistent="1" Value="1110820127.788">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1120
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeStart3"
Persistent="1" Value="1110820127.788">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1168
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeStart4"
Persistent="1" Value="1110820127.788">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1216
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeStart5"
Persistent="1" Value="1110820127.788">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1264
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeElapse"
Persistent="1" Value="1110820122.788">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1312
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeElapse1"
Persistent="1" Value="1107642785.562">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1360
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeElapse2"
Persistent="1" Value="70.125">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1408
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeElapse3"
Persistent="1" Value="60">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1456
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeElapse4"
Persistent="1" Value="1107642785.562">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1504
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeElapse5"
Persistent="1" Value="25.1559998989105">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1552
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeDelay"
Persistent="1" Value="20">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1600
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeDelay1"
Persistent="1" Value="1107642785.562">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1648
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeDelay2"
Persistent="1" Value="45.6399998664856">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,1696
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeDelay3"
Persistent="1" Value="20">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,2368
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeDelay4"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,2416
80,32" DataType="integer" Enabled="1" Inner="0" Name="varTimeDelay5"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="variable" Category="" Coordinates="16,2464
80,32" DataType="integer" Enabled="1" Inner="0" Name="varStage"
Persistent="1" Value="1">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="output" Category="" Coordinates="16,2560
80,32" DataType="integer" Enabled="1" Inner="0" Name="outTowerFan1Enable"
Persistent="1" Value="1">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="output" Category="" Coordinates="16,2608
80,32" DataType="integer" Enabled="1" Inner="0" Name="outTowerFan2Enable"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
<EquipmentProperty AccessType="output" Category="" Coordinates="16,2656
80,32" DataType="integer" Enabled="1" Inner="0" Name="outTowerFan3Enable"
Persistent="1" Value="0">
<BackwardReferences/>
<Reference ObjectKey="" PropertyName=""/>
</EquipmentProperty>
</EquipmentPropertiesEx>
<GeneralProperties Attr="1" InstanceNumber="21223" IsConfigured="0"
ObjectName="TowerFan_Control" ObjectType="203" SchemaVer="1.4"
TraceOptions="0">
<Description/>
</GeneralProperties>
</EquipmentObject>

"Martin Honnen" wrote:
>

dotnetnoob wrote:
i keep getting Object references not set to an instance of an object from
Dim xDoc As New Xml.XmlDocument
xDoc.Load(CStr(arlsFilePath.Item(x)))
Dim xNode As Xml.XmlNode =
xDoc.SelectSingleNode("/EquipmentObject/EquipmentPropertiesEx/EquipmentProperty[@Name='" + CStr(arlsVarName.Item(x)) + "']/Reference/@ObjectKey")
xNode.Value = str2

On which line do you get the error, on the line above? That means that
SelectSingleNode with the XPath expression passed in has not found a
matching node and xNode is Nothing in VB.
We would need to see the XML or relevant parts of it to be able to say
why the XPath does not find a node.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 7 '06 #4
It's possible that during your function call that CStr(arlsVarName.Item(x)) is not returning the value you are expecting.

When you tested the XPath in XMLSpy, did you hardcode in the string you expected to be returned by the above code, or was it runnning your code?

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Aug 7 '06 #5


dotnetnoob wrote:

this is the xml strucutre:

<EquipmentPropertiesEx>
So that starts with EquipmentPropertiesEx but then ends with
</EquipmentObject>
EquipmentObject which is not even well-formed XML and any XML parser
will refuse that.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 8 '06 #6
yes, it return what i expecting and the xpath query work in one section of
the code and write to the xml file but when i try to run it against different
arugment, it gave me the object reference not set error here is the code

Dim x As Integer = 0
Dim y As Integer = 0
If CStr(arlsType.Item(x)) = "Value Point" Then
Do
Dim str1, str2 As String
str1 = CStr(arlsFilePath(x))
str1 = str1.Substring(0, str1.LastIndexOf("."))
str1 = str1.Remove(0, 42)
str1 = str1.Substring(0, str1.LastIndexOf("_"))
str2 = str1 + "_" + "217" + "." + CStr(arlsInstNum.Item(x))
Dim xDoc As New Xml.XmlDocument
xDoc.Load(CStr(arlsFilePath.Item(x)))
Dim xObjKey As Xml.XmlNode =
xDoc.SelectSingleNode("/EquipmentObject/EquipmentPropertiesEx/EquipmentProperty[@Name='" + CStr(arlsVarName.Item(x)) + "']/Reference/@ObjectKey")
xObjKey.Value = str2
Dim xPropName As Xml.XmlNode =
xDoc.SelectSingleNode("/EquipmentObject/EquipmentPropertiesEx/EquipmentProperty[@Name='" + CStr(arlsVarName.Item(x)) + "']/Reference/@PropertyName")
xPropName.Value = "ValuePointProperties.PresentValue"
xDoc.Save(CStr(arlsFilePath.Item(x)))
x += 1
Loop Until x = arlsType.Count
Else
x += 1
End If

If CStr(arlsType.Item(y)) = "Bacnet Point" Then
Do
Dim str1, str2 As String
str1 = CStr(arlsFilePath(y))
str1 = str1.Substring(0, str1.LastIndexOf("."))
str1 = str1.Remove(0, 42)
str2 = str1 + "_" + CStr(arlsBacNetType.Item(y)) + "." +
CStr(arlsInstNum.Item(y))
Dim xDoc As New Xml.XmlDocument
xDoc.Load(CStr(arlsFilePath.Item(y)))
Dim xObjKey As Xml.XmlNode =
xDoc.SelectSingleNode("/EquipmentObject/EquipmentPropertiesEx/EquipmentProperty[@Name='" + CStr(arlsVarName.Item(y)) + "']/Reference/@ObjectKey")
xObjKey.Value = str2
Dim xPropName As Xml.XmlNode =
xDoc.SelectSingleNode("/EquipmentObject/EquipmentPropertiesEx/EquipmentProperty[@Name='" + CStr(arlsVarName.Item(y)) + "']/Reference/@PropertyName")
xPropName.Value = "PresentValue"
xDoc.Save(CStr(arlsFilePath.Item(y)))
y += 1
Loop Until y = arlsType.Count
Else
y += 1
End If

the first if loop and it run fine but when i run the second if loop, it gave
me that error. i'm puzzled

"Greg Collins [Microsoft MVP]" wrote:
It's possible that during your function call that CStr(arlsVarName.Item(x)) is not returning the value you are expecting.

When you tested the XPath in XMLSpy, did you hardcode in the string you expected to be returned by the above code, or was it runnning your code?

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Aug 8 '06 #7
the weird part is i will get the object reference not set to an instance of
an object but the code will write to the xml file

"Greg Collins [Microsoft MVP]" wrote:
It's possible that during your function call that CStr(arlsVarName.Item(x)) is not returning the value you are expecting.

When you tested the XPath in XMLSpy, did you hardcode in the string you expected to be returned by the above code, or was it runnning your code?

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Aug 8 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Richard Trahan | last post: by
3 posts views Thread by Frankie | last post: by
reply views Thread by XML newbie: Urgent pls help! | last post: by
2 posts views Thread by =?Utf-8?B?bWFib25k?= | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

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.