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

Need XPath help

Hi,

I am trying to use an XmlDocument object to manipulate the default database
instance node of the enterprise template library dataConfiguration section
from a custom installer step:

<?xml version="1.0" encoding="utf-8"?>
<dataConfiguration>
<xmlSerializerSection
type="Microsoft.Practices.EnterpriseLibrary.Data.C onfiguration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=1.1.0.0, Culture=neutral,
PublicKeyToken=null">
<enterpriseLibrary.databaseSettings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
defaultInstance="AdessoOdbc"
xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">
<databaseTypes>

I have tried several XPath queries but I am not having any luck fetching the
"defaultInstance" attribute - xpath seems to be unhappy about the '.' in the
"enterpriseLibrary.databaseSettings" node name. For example this code:

XmlNode node =
xml.SelectSingleNode("dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings");

does NOT return "enterpriseLibrary.databaseSettings" node - it returns null.
Any ideas on how I can get to the defaultInstance attribute?
Nov 17 '05 #1
2 1530
Richard wrote:
Hi,

I am trying to use an XmlDocument object to manipulate the default database
instance node of the enterprise template library dataConfiguration section
from a custom installer step:

<?xml version="1.0" encoding="utf-8"?>
<dataConfiguration>
<xmlSerializerSection
type="Microsoft.Practices.EnterpriseLibrary.Data.C onfiguration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=1.1.0.0, Culture=neutral,
PublicKeyToken=null">
<enterpriseLibrary.databaseSettings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
defaultInstance="AdessoOdbc"
xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">
<databaseTypes>

I have tried several XPath queries but I am not having any luck fetching the
"defaultInstance" attribute - xpath seems to be unhappy about the '.' in the
"enterpriseLibrary.databaseSettings" node name. For example this code:

XmlNode node =
xml.SelectSingleNode("dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings");

does NOT return "enterpriseLibrary.databaseSettings" node - it returns null.
Any ideas on how I can get to the defaultInstance attribute?

Hi,

It's not the dot.

The enterpriseLibrary.databaseSettings is in a different namespace,
declared by the
xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data"
attribute.

You have to use a nametable/namespacemanager to assign a prefix for this
namespace, after that you can use xpath queries it like this:

XmlNode node =
xml.SelectSingleNode("dataConfiguration/xmlSerializerSection/myprefix:enterpriseLibrary.databaseSettings");

If you need help with the C# part, let me know...

Luck, Wiebe
Nov 17 '05 #2
Hi,
Will this be the right way to do this? :

XmlTextReader xreader = new XmlTextReader( xmlfilename );
XmlNamespaceManager nsm = new XmlNamespaceManager(xreader.NameTable );
nsm.AddNamespace("abc",
"http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data");
XmlNode node =
doc.DocumentElement.SelectSingleNode("xmlSerialize rSection/abc:enterpriseLib
rary.databaseSettings", nsm);

and than you can write:

node.Attributes.GetNamedItem("defaultInstance").Va lue

to get the value.

Ab.
http://joehacker.blogspot.com

"Wiebe Tijsma" <wi*********@CAPITALStijsma.com> wrote in message
news:#4*************@tk2msftngp13.phx.gbl...
Richard wrote:
Hi,

I am trying to use an XmlDocument object to manipulate the default database instance node of the enterprise template library dataConfiguration section from a custom installer step:

<?xml version="1.0" encoding="utf-8"?>
<dataConfiguration>
<xmlSerializerSection
type="Microsoft.Practices.EnterpriseLibrary.Data.C onfiguration.DatabaseSetti
ngs, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null">
<enterpriseLibrary.databaseSettings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
defaultInstance="AdessoOdbc"
xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data"
<databaseTypes>

I have tried several XPath queries but I am not having any luck fetching
the "defaultInstance" attribute - xpath seems to be unhappy about the '.' in the "enterpriseLibrary.databaseSettings" node name. For example this code:

XmlNode node =
xml.SelectSingleNode("dataConfiguration/xmlSerializerSection/enterpriseLibra
ry.databaseSettings");
does NOT return "enterpriseLibrary.databaseSettings" node - it returns null. Any ideas on how I can get to the defaultInstance attribute?

Hi,

It's not the dot.

The enterpriseLibrary.databaseSettings is in a different namespace,
declared by the

xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data" attribute.

You have to use a nametable/namespacemanager to assign a prefix for this
namespace, after that you can use xpath queries it like this:

XmlNode node =
xml.SelectSingleNode("dataConfiguration/xmlSerializerSection/myprefix:enterp
riseLibrary.databaseSettings");
If you need help with the C# part, let me know...

Luck, Wiebe

Nov 17 '05 #3

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

Similar topics

4
by: MegaZone | last post by:
I'm having some issues with PHP DOMXML - in particular the get_elements_by_tagname method. Now, the PGP docs on this are, well, sparse, so maybe I'm just doing something stupid. I thought this...
0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
2
by: Jaunedeau | last post by:
I have some XML that must look like this : <movies> <movie id="1"> <actor preferredMovieId="1"> <actor preferredMovieId="2"> <actor preferredMovieId="3"> </movie> <movie id="2"> <actor...
2
by: AGB | last post by:
Hi all, I have the following simple XML file. I would like to load all the values in the Name nodes into a drop-down list box: <?xml version="1.0" encoding="utf-8" ?> <OutlineCodeNames>...
3
by: Shawn | last post by:
Hi. I have an XML file that looks like this: <?xml version="1.0" encoding="utf-16"?> <Transfer> <Config xmlns="http://www.mysite.com/Transfer/"> <site>NY</site> </Config> </Transfer> I'm...
5
by: Chua Wen Ching | last post by:
Hi, I read from this tutorial at codeproject Question A: http://www.codeproject.com/csharp/GsXPathTutorial.asp regarding xpath.. but i try to apply in my situation, and can't get it...
0
by: Joe | last post by:
Hi Could someone give me a simple explaination of this XSD which is a DataSet with relations The tables are fgFAT,e0,e1,e2,e3 which I have deleted I am trying to make sense of the part below...
1
by: jesper_lofgren | last post by:
Hello, i need to help here. I have a xmlnode as you can se below (full xml is in the bottom). I wonder how i can get the values inside the CSammanstallningLista . <CSammanstallning...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.