473,226 Members | 1,532 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,226 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 2113


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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.