473,395 Members | 1,504 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,395 software developers and data experts.

Problem getting node

I'm having a problem in by VB.net 2005 application. When i try to get a node
from my app.config file the node come back with "nothing". The xmldocment
loads OK, but I can't retrive a node. The app.config file is listed below
and the code is listed below that, the line with "-->>" is where i try to
get the node. Can anyone see where I'm going wrong.

A dump of the xmlDocument is listed below the code.
Note: "MyKey" is set to "Reports"

Thank,
John
jo***@iirp.coedu.usf.edu
App.config file
----------------------------------------------------------------------------------
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
</configSections>
<connectionStrings>
<add name="My.MySettings.DataConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data
Source=C:\Ingredients_Data.mdb" providerName="System.Data.OleDb" />
</connectionStrings>
<appSettings>
<add key="Reports" value="C:\current\Reports.xls" />
<add key="Calendar" value="C:\current\Calendar.xls" />
<add key="ClaimContinuum"
value="C:\current\ClaimContinuumReportBuild.xls" />
</appSettings>
</configuration>
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
Public Function Save_Config_Parameter(ByVal MyKey As String, ByVal MyValue
As String) As String

Dim XmlDocument As New XmlDocument
Dim XmlNode As XmlNode
Dim XmlRoot As XmlNode
Dim XmlKey As XmlNode
Dim XmlValue As XmlNode

Save_Config_Parameter = ""
XmlDocument.Load(AppDomain.CurrentDomain.SetupInfo rmation.ConfigurationFile)--->> XmlNode =XmlDocument.DocumentElement.SelectSingleNode("//configuration/appSettings/add[@key=""" & MyKey & """]") If XmlNode Is Nothing Then ' The node does not exist, let's create it XmlNode = XmlDocument.CreateNode(XmlNodeType.Element, "add", "") ' Adding the Key attribute to the node, keep in mind, Xml tokens are casesensitive ' We should use 'key' instead of 'Key' XmlKey = XmlDocument.CreateNode(XmlNodeType.Attribute, "key", "") XmlKey.Value = MyKey XmlNode.Attributes.SetNamedItem(XmlKey) ' Adding the key value, once again, remember that Xml tokens are casesensitive XmlValue = XmlDocument.CreateNode(XmlNodeType.Attribute, "value", "") XmlValue.Value = MyValue XmlNode.Attributes.SetNamedItem(XmlValue) ' Add the new node to the root XmlRoot =XmlDocument.DocumentElement.SelectSingleNode("/configuration/appSettings") If Not XmlRoot Is Nothing Then XmlRoot.AppendChild(XmlNode) Else Save_Config_Parameter = "ERROR" End If Else ' ' The node exist, save the new value ' XmlNode.Attributes.GetNamedItem("value").Value = MyValue End If XmlDocument.Save(Application.ExecutablePath & ".config") XmlDocument = NothingEnd Function========================================== =============================>? XmlDocument{System.Xml.XmlDocument} Attributes: Nothing BaseURI: "file:///C:/John/bin/Debug/App.vshost.exe.config" ChildNodes: {System.Xml.XmlChildNodes} DocumentElement: {System.Xml.XmlElement} DocumentType: Nothing FirstChild: {System.Xml.XmlDeclaration} HasChildNodes: True Implementation: {System.Xml.XmlImplementation} InnerText: "" InnerXml: "<?xml version="1.0"?><configurationxmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"><configSections></configSections><connectionStrings><addname="My.MyS ettings.DataConnectionString"connectionString="Pro vider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Ingred ients_Data.mdb" providerName="System.Data.OleDb"/></connectionStrings><appSettings><add key="Reports"value="C:\current\Reports.xls" /><add key="Calendar"value="C:\current\Calendar.xls" /><add key="ClaimContinuum"value="C:\current\ClaimContinu umReportBuild.xls"/></appSettings></configuration>" IsReadOnly: False Item: In order to evaluate an indexed property, the property must bequalified and the arguments must be explicitly supplied by the user. LastChild: {System.Xml.XmlElement} LocalName: "#document" Name: "#document" NamespaceURI: "" NameTable: {System.Xml.NameTable} NextSibling: Nothing NodeType: Document {9} OuterXml: "<?xml version="1.0"?><configurationxmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"><configSections></configSections><connectionStrings><addname="My.MyS ettings.DataConnectionString"connectionString="Pro vider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Ingred ients_Data.mdb" providerName="System.Data.OleDb"/></connectionStrings><appSettings><add key="Reports"value="C:\current\Reports.xls" /><add key="Calendar"value="C:\current\Calendar.xls" /><add key="ClaimContinuum"value="C:\current\ClaimContinu umReportBuild.xls"/></appSettings></configuration>" OwnerDocument: Nothing ParentNode: Nothing Prefix: "" PreserveWhitespace: False PreviousSibling: Nothing SchemaInfo: {System.Xml.Schema.XmlSchemaInfo} Schemas: {System.Xml.Schema.XmlSchemaSet} Value: Nothing>

Apr 21 '06 #1
1 2870
Hi John

The problem I believe lies in the fact that your XML falls under the
default namespace
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"

And your xpath expression is not namespace aware.

That is why your Xpath expression doesn't work as you hope - i.e
XmlNode =
XmlDocument.DocumentElement.SelectSingleNode("//configuration/appSettings/add[@key="""
& MyKey & """]")

i.e this always sets XmlNode to null

A quick work around would be to remove the namespace from your Xml to
get your code rolling and xpath working.

- however as has been quoted elsewhere on this group
"Changing the XML to remove xmlns is usually not the right way to solve
the problem but rather an attempt to circumvent the problem."

For more info on namespaces & xpath in .NET read:
Article by Martin Honnen -
http://www.faqts.com/knowledge_base/.../34022/fid/616
&
"XPath Queries with Namespaced Mapped Prefixes" in MSDN

Dickster

Apr 21 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ayende Rahien | last post by:
Serious problem I'm using Chris Lovett's SgmlReader class SgmlReader sr = new SgmlReader(); XmlDocument xdoc = new XmlDocument(); sr.DocType = "HTML"; sr.InputStream = new...
5
by: NM | last post by:
Hi All, I am having a peculiar problem. I used to link between intel fortran 7.0 and g++ without any problem. Now the intel compiler is upgraded to version 9.0 and I am getting segmenatation...
3
by: Saradhi | last post by:
Hi All, Here I am facing a performance problem with the TreeView Node renaming. I am displaying a hierarchy Data in a treeview in my Windows C# Application. My tree view represents an...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
1
by: infiniti | last post by:
Hi, I am trying to transform this xml section using xsl, but there is a glitch in the xsl file which I do not know how to rectify. Any help is appreciated. XML: <?xml version="1.0"...
3
by: vdileep | last post by:
Hi, I have 3 systems with db2 running on AIX. We take online backup on weekdays and offline on saturday. For the past two weeks the offline backup is getting terminated after exactly 2 hours 13...
1
by: Rebecca Tsukalas | last post by:
Hello, I have a problem concerning removeChild. This is the XML structure I use with php: <xml_thing <language1 <site>bla1</site <site>bla2</site <site>bla3</site </language1
5
by: =?Utf-8?B?VGhlIE1hbiBGcm9tIFNRTA==?= | last post by:
I'm having the darndest XML config file problem that I really need help with. I'm supporting a .NET 1.1 desktop application with its own config file, and I implement IConfigurationSectionHandler...
6
by: Lars | last post by:
Hi all If this is the wrong list for beginners trouble I apologize. please refer to me the correct list in such case. I am trying to create a simple linked list but I keep getting segmentation...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.