473,405 Members | 2,310 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,405 software developers and data experts.

XML XMLNS breaks XPath reference

I have the following XML:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key="Main.ConnectionString" value="foo">
</appSettings>
</configuration>

The following XPath works 'only' when the above xmlns reference is removed:
//configuration/appSettings/add[@key='Main.ConnectionString']/@value

Any work arounds to this problem?

Martynwb
Oct 5 '07 #1
3 2474
jkmyoung
2,057 Expert 2GB
Assuming you're using .Net, you would need a namespace manager.

eg. declare:
xmlns:ncf="http://schemas.microsoft.com/.NetConfiguration/v2.0"
like so
XmlNamespaceManager xmlns = new XmlNamespaceManager()
xmlns.AddNamespace("ncf", "http://schemas.microsoft.com/.NetConfiguration/v2.0");

and change your xpath accordingly:
//ncf:configuration/ncf:appSettings/ncf:add[@key='Main.ConnectionString']/@value
Oct 5 '07 #2
This application is actually an MSBuild application with no assocaited .NET application. It updates the config file but cannot change the underlying code. Can this functionality be offered in MSBuild?

Thanks

Martyn
Oct 9 '07 #3
jkmyoung
2,057 Expert 2GB
I have no experience with MSBuild.
An unpretty xpath that should work is:

//*[local-name()='configuration']/*[local-name()='appSettings']/*[local-name()='add'][@key='Main.ConnectionString']/@value
Oct 9 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: jorgen.wahlund | last post by:
Hi I have problems with transforming a xml document with Xalan and javax.xml.Transformer. Following xsl is used: <xsl:stylesheet version='1.0'...
4
by: Gismo | last post by:
I have got file raport.rld which is an XML file generated by MS Reporting Services. The problem is: in this file are tags from two different namespaces ...
2
by: Linda Boumarafi | last post by:
Hi, This is a newbie question to XMLNS. I just finished the article on "XML Namespaces and How They Affect XPath and XSLT" by Dare Obasanjo and I'm pretty sure I understand the problem. I just...
11
by: EAI | last post by:
Hi All, I have a XML of the following form <?xml version="1.0"?> <xxxx xmlns="http://xxx.xxx.com"> .... </xxxx> When I try to read xml using SelectSingleNode, I am getting exception
4
by: David S. Alexander | last post by:
I am trying to transform XML to XML using an XSLT in C#, but the root node of my XML is not being matched by the XSLT if it has an xmlns attribute. Am I handling my namespaces incorrectly? My C#...
3
by: olympus_mons | last post by:
Hi all, my XML looks like: <root xmlns="tempuri.org"> <result xmlns=""> <date>2006-09-14</date> <status>ok</status> </result> </root>
2
by: Jason Zhou | last post by:
Hi, I am receiving an XML document from other system, and I am using xPath to search one of the node in the document. For example, the xml document like this: <Company> <Employees>...
1
by: Jazper | last post by:
hi i have a problem querying a simple atom-feed by xpath using the XmlDocument. i'm googleing for hours now and can't get a solution: --- Code --- XmlDocument doc = new XmlDocument();...
1
by: nwbabcock | last post by:
I'm using XmlSerializer to deserialize an xml into classes. The error I recieve is: Exception:There is an error in XML document (2, 2). Inner Exception: <applications...
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:
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
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,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.