Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 7th, 2006, 04:45 PM
dotnetnoob
Guest
 
Posts: n/a
Default 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

  #2  
Old August 7th, 2006, 05:15 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: how do i change a value of a node?



dotnetnoob wrote:
Quote:
i keep getting Object references not set to an instance of an object from
Quote:
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/
  #3  
Old August 7th, 2006, 05:45 PM
Greg Collins [Microsoft MVP]
Guest
 
Posts: n/a
Default Re: how do i change a value of a node?

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 )


  #4  
Old August 7th, 2006, 09:55 PM
dotnetnoob
Guest
 
Posts: n/a
Default Re: how do i change a value of a node?

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:
Quote:
>
>
dotnetnoob wrote:
>
Quote:
i keep getting Object references not set to an instance of an object from
>
Quote:
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/
>
  #5  
Old August 7th, 2006, 11:05 PM
Greg Collins [Microsoft MVP]
Guest
 
Posts: n/a
Default Re: how do i change a value of a node?

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 )


  #6  
Old August 8th, 2006, 01:25 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: how do i change a value of a node?



dotnetnoob wrote:

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


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
  #7  
Old August 8th, 2006, 03:15 PM
dotnetnoob
Guest
 
Posts: n/a
Default Re: how do i change a value of a node?

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:
Quote:
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 )
>
>
>
  #8  
Old August 8th, 2006, 03:15 PM
dotnetnoob
Guest
 
Posts: n/a
Default Re: how do i change a value of a node?

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:
Quote:
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 )
>
>
>
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles