473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 2120


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Trahan | last post by:
(This is a repost -- the original got tucked away into an old thread because I used the same Subject name.) I'm trying to change the document title to add an asterisk when the document becomes...
2
by: Rick | last post by:
I have an XML document that is generated from Infopath, I need to change the value of a namespace that is defined in a node in the form: <xsf:xDocumentClass "xmlns:my=valuehere">. when i navigate...
0
by: beanweed | last post by:
BACKGROUND ---------- I have an ASP.NET application having two panels. In one panel, an XML document, transformed using xsl, is displayed. In the other panel are some controls that allow a user...
3
by: Frankie | last post by:
I'm writing a small utility app (C# Windows forms) used to create new ASP.NET Web sites. This utility needs to be able to change existing values in an existing Web.config. Please note: I do NOT...
0
by: XML newbie: Urgent pls help! | last post by:
HI, I am working on VB.Net.My program connects to the remote host, once the login values are verified, it sends the SessionID. My problem is Although in "Logindom" variable( in the Auto window),...
0
by: vincent90152900 | last post by:
http://vincent90152900.myweb.hinet.net/test.htm Following is my codes and I don’t know how to make the line appeared? <asp:TreeView ID="TreeView1" runat="server"...
4
by: RP | last post by:
I have a TreeView control. When a user clicks on a node, it must change color. I did: TreeView1.SelectedNode.ForeColor = colors.Blue; However, it must change the other nodes color to black,...
1
SamKL
by: SamKL | last post by:
Hey, I'm no expert on PHP, and I have somewhat of an understanding of object oriented code. Anyway, getting right to the problem. I'm using PHP4, so base it off of that. Basically I have 2...
2
by: =?Utf-8?B?bWFib25k?= | last post by:
I'm using a treeview control. One parent node, several child nodes, several grandchild nodes. Each of the nodes has a checkbox. My question, when the user changes the check value of one of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.