why namespace make xpath fail ????

hello,

please consider the following piece of XML:

<?xml version="1.0" encoding="utf-8"?>
<definition>
	<connexion type="sql">
		<serveur>localhost\srv2005</serveur>
		<utilisateur>ADMIN</utilisateur>
		<mdp>****</mdp>
		<database>test2008loc</database>
	</connexion>
</definition>

then the following piece of c#

using (XmlReader xrFDPXSD = XmlReader.Create(xmlFileName)) {
    XElement xeFDPXSD = XElement.Load(xrFDPXSD);

    XElement xe = xeFDPXSD.XPathSelectElement("/connexion", nsMan);
}

give me a not null xe.

BUT if i use the following xml

<?xml version="1.0" encoding="utf-8"?>
<definition xmlns="domain.tld">
	<connexion type="sql">
		<serveur>localhost\srv2005</serveur>
		<utilisateur>ADMIN</utilisateur>
		<mdp>****</mdp>
		<database>test2008loc</database>
	</connexion>
</definition>

with the same C# code or with the following c# code

using (XmlReader xrFDPXSD = XmlReader.Create(xmlFileName)) {
    XElement xeFDPXSD = XElement.Load(xrFDPXSD);
    XmlNameTable nameTable = xrFDPXSD.NameTable;
    XmlNamespaceManager nsMan = new XmlNamespaceManager(nameTable);
    nsMan.AddNamespace("", "http://domain.tld/");

    XElement xe = xeFDPXSD.XPathSelectElement("/connexion", nsMan);
}

then xe is NULL !!!

thanks in advance for any advice

thierry
0
11/9/2009 9:44:02 AM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
774 Views

Similar Articles

[PageSpeed] 24

thierry wrote:

> <definition xmlns="domain.tld">
> 	<connexion type="sql">
> 		<serveur>localhost\srv2005</serveur>
> 		<utilisateur>ADMIN</utilisateur>
> 		<mdp>****</mdp>
> 		<database>test2008loc</database>
> 	</connexion>
> </definition>
> 
> with the same C# code or with the following c# code
> 
> using (XmlReader xrFDPXSD = XmlReader.Create(xmlFileName)) {
>     XElement xeFDPXSD = XElement.Load(xrFDPXSD);
>     XmlNameTable nameTable = xrFDPXSD.NameTable;
>     XmlNamespaceManager nsMan = new XmlNamespaceManager(nameTable);
>     nsMan.AddNamespace("", "http://domain.tld/");

Use a prefix e.g.
       nsMan.AddNamespace("df", "domain.tld");

>     XElement xe = xeFDPXSD.XPathSelectElement("/connexion", nsMan);

       XElement xe = xeFDPXSD.XPathSelectElement("df:connexion", nsMan);

As you are already using LINQ to XML you could of course use LINQ to XML 
queries instead of XPath queries e.g.
       XNamespace df = xeFDPXSD.Name.Namespace;
       XElement xe = xeFDPXSD.Element(df + "connexion");

-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/
0
mahotrash (1778)
11/9/2009 11:35:22 AM
Reply:

Similar Artilces:

Why is XMLSchema namespace so different than my custom namespace?
Below is a snippet that I'm sure is quite familiar to most ... <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" Here, I've given the XMLSchema namespace the prefix 'xsd', and with that, I can reference datatypes within the XMLSchema namespace ... i.e., xsd:string. That's great, but why can't I use that same notation, to reference dataypes in a homegrown schema ... WITHOUT doing an <import> or <include>? Is the XMLSchema (and the XMLSchema-instance) sort of "built-in" to XML tools, such that they don't need to go find th...

How do i make grid map to input cord for a game
I am playing a war game and want to enter my findings with the cords, but cannot find the way to make the map in excell ...

is it possible to make a database secure after creating it as unsecure?
I am new in the security option of the databases. I started to study security and what i learned at the beginning is to create a new workgroup and create a new user to be replaced with the default Admin user who is member of default Admins group. My question... If i create a new unsecure database with all tables, queries and forms required as being default Admin user under the default Admins group, can I make it secure completely then? I mean, can I create a new workgroup and can i specify a new owner for this unsecure database, so that it will be completely secure? Is it clear? Thanks Hi...

How to make a waterfall chart
I have to create a Waterfall chart (not to be confused with a cascade chart) like the one shown at http://www.ozgrid.com/Services/excel-waterfall-chart.htm. This is just a one-time deal, and I don't feel like buying the add-in. I would rather learn how to do it myself. Does anybody know how? Thanks! Lucas Bravo Hi Lucas have a look at http://www.tushar-mehta.com/excel/charts/waterfall/index.htm http://peltiertech.com/Excel/Charts/DummySeries.html#Falls http://peltiertech.com/Excel/Charts/DummySeries.html#Fall2 -- Regards Frank Kabel Frankfurt, Germany Lucas Bravo wrote: > I have ...

how to make Under invoice formula
Please help me how to make formula if as following case? Thank you very much in advance to expert helpers. I want divide a total amount of many diffrent product, in according to there actual value of product of each product. as following example. Actual invoice and value & The actual amount Product quantity unit price total price Bag 1000 2.1 $2,100 shoes 5000 3.1 $15,500 blanket 8000 4.32 $34,560 jacket 1500 1.8 $2,700 bed sheet 6000 ...

Namespaces
Is there any documentations that will explain the Namespaces better or any help file? -- Matthew Heinrich Casino Queen Inc. Development Team ...

XPath question
Ok here is my XML structure : <Files> <File Name="One.txt"> <Client Name="test1"> <Errors> <OtherErrorIDs> <OtherErrorID>1</OtherErrorID> <OtherErrorID>2</OtherErrorID> <OtherErrorID>4</OtherErrorID> </OtherErrorIDs> </Errors> </Client> <Client Name="test2"> <Errors> <OtherErrorIDs> ...

Fields in an Excel DB merged to make slides in PowerPoint or Publisher
Please, we use MailMerge to "merge" data from a file into a Word document. Is there a way to merge data in an Excel file to "boxes" in a Power Point or Publisher slide such that 'n' slides are created from 'n' sets of data in an Excel file. Would like to pull images, their address being in an Excel field, along with data about the image. The Excel field could be a pointer to another DB. Am I clear on this? If so, thank you, I look forward to your advice. Kind Regards, Wayne Dengel ...

make process invisible
How can I make an application that does not appear in the windows task manager? Thanks. Jess "Jessica Weiner" <jessica@gmail.com> wrote in message news:MdZuf.8396$UF3.5952@newssvr25.news.prodigy.net... > How can I make an application that does not appear in the windows task > manager? > By using a rootkit. If you are found out, though, your name will be mud. -- David MUDs are an old, honored technology. Don't compare the sort of sociopath who would use a rootkit to a respectable game technology.... :-) joe On Wed, 4 Jan 2006 16:02:54 -0800,...

Make $260 a week minimum
biglegalbuds hey all this affiliate program is rated the 2nd best program on the net for targetted customers, our herbal products attract interest and sales from over 75% of the world of smokers. the marijuana and extacy alternatives that start at a low $29 a ounce including postage attracts a sales ratio of 1 in 6 visitors are a sale, with a average sale of $60 grabs you a $15 commission, if your site is good and you receive over 100 hits a day you can expect a easy $100 min a day in sales visit now at http://www.biglegalbuds.com and after browsing my pa...

How can I make the DOCUMENTS folder always the default folder?
I have a friend with windows xp and when he saves documents it sometimes goes into a folder that may look like this: 96453312gh or similar, other times it goes into the proper documents folder. How can I help him to let his created documents always go to My Documents? ( because if it went to the other above example folder, he can never find it again) Ritter197 wrote: > I have a friend with windows xp and when he saves documents it sometimes > goes into a folder that may look like this: 96453312gh or similar, other > times it goes into the proper documents folder. ...

make a splash screen appear first
When I open my app I have it go full screen and remove all the furniture (including menus) but before it does it you see everything first. Is there any way yo just make it appear (preferably just the splash screen first) and then full screen behind the splash screen (or after whichever) as the first thing you see without the excel pre-amble (I want to demo it to a potential customer and don't want him to know it's excel, if he buys I will get it converted:) Thanks for your suggestions, Mark convert the file to what? -- tx12345 --------------------------------------------...

Group header makes report too long
I am working on a report for a list of items grouped by part number, in the group header i have the part number and description and in the detail i have the Serialized info in a stepped type report. this is great for groups that have 20 or 30 records but the 5 or 6 hundred records with one detail record all become Two Liners wich add 20 pages to the report. I would like to get rid of the group header and add a part number and description control to the detail section but i ONLY want the first record in each series to have these controls visible so that each new series is easily ...

word pad and encoding is making is making viewing hard
When i go to view pdf files the encoding ask for choice of making it readable. I do not want this interference and need to make possible to just open up pdf files. It was also viewing in wordpad which i do not want to do. Is there some tab that i'm missing or do i need to configure some thing? On Thu, 26 Nov 2009 08:49:02 -0800, Rodney d <Rodneyd@discussions.microsoft.com> wrote: >When i go to view pdf files the encoding ask for choice of making it readable. >I do not want this interference and need to make possible to just open up >pdf files. >It was also ...

Making a slash overprint
How can I make a slash overprint to a sign? Such things as "SOLD, CENSORED, CANCELLED", etc on top of the original sign such as realtors do. I am using PUB2000. Use the line tool at the left. -- Don Vancouver, USA "Mark H White" <MarkHWhite@discussions.microsoft.com> wrote in message news:DE6C44D7-F39E-4DF8-9DAC-D04C5D6F7CCA@microsoft.com... > How can I make a slash overprint to a sign? Such things as "SOLD, > CENSORED, > CANCELLED", etc on top of the original sign such as realtors do. I am > using > PUB2000. Mark H White wr...

New install of IE8 makes my disk light flash 12-20-09
I usually use Firefox but I recently installed IE8. If I launch IE8 with a blank home page then my hard disk starts to do a lot of work. The hard disk works all the time while IE8 is launched even if I don't browse anything or touch IE8. When I close IE8 the disk activity stops. I hope IE8 isn't trying to index its way through my disk data because I have 500 GB! Could IE8 be downloading a lot of special data to identify dangerous web sites like Chrome does? I can't see any data being downloaded but maybe IE8 is doing a hidden download or something. A pop-up...

How do I make the location box bigger?
I am trying out the Excel 2010 beta and having missed out 2007 I am trying to get to grips with the ribbons, probably the most cumbersome way of accessing controls ever devised, but that is beside the point. One of my most used controls in Excel was the 'address bar', it was the simplest way to copy paths into emails for other people on the network, this has now become the 'location box' or 'document location' and it can be added to the quick access toolbar. The problem is it's really small and when dealing with long network paths it is nice to be ab...

XmlSerializer and blank namespace
In 1.1, I could do this: XmlSerializer xs = new XmlSerializer(typeof(Doodad)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.add("", ""); xs.Serialize(writer, doodad, ns); and it produced: <doodad> .... </doodad> In 2.0, the same code produces: <doodad xmlns=""> .... </doodad> Any idea why and how to get rid of the blank namespace? ...

Making Personal Calender Viewable via the WEB but NOT Editable via
Upfront: I am in the military and new to my job as Network Administrator at my unit. We are a part of a larger network for the fort and I do not have administrator priviledges to the Exchange Server or most things outside of our unit. I am seeking solutions and resources in order to give my request to the network admins the best possible chances of getting done. --------------------------------------------------------------------- Currently we have a user account that is simply the calender for the unit. It is a shared calendar so everyone can see it at work with only a few individua...

Failing to import the sample database: Adventure Works Cycle
I have installed the MSDN Subscriber version of MSCRM. I have installed the license key and have been awarded 6 professional key licenses. I have installed the system and is working. When I want to import the sample database I am getting an error that I don't have enough licenses. What should I do. Joachim, Did you already add the users to CRM? This is a common mistake people make. The sample data load will add the users into CRM and assign licenses to them. If you already did this, the 5 licenses are no longer available. You either need to remove the licenses form the users and...

Send receive operation failed
I have an error that comes up when i hit send/receive. It says 'operation failed'. There is nothing else with the message, just an ok button. I have tried microsoft knowledge base article http://support.microsoft.com/default.aspx?scid=kb;en- us;312354 but that doesn't help, it fixes the error that says 'The operation failed. An object could not be found.' but not mine, i tried it and it didn't work. I am using windows 2000 and office xp. This error has only been happening recently. Can anyone help me? Thanks, Matt ...

XML namespaces and XSD.exe
Oh boy i'm getting tangled in knots here. I have a schema which contains <xs:schema targetNamespace="http://Southend.Schemas.PAS/PASPatientDemographics.xsd" id="PASPatientDetails" xmlns:sh="http://Southend.Schemas.PAS/PASPatientDemographics.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> now i used the xsd.exe and it now generates elements when I serilaize the class I get <RequestingPatient_ID xmlns="">D1234567890</RequestingPatient_ID> So each emlement contains xmlns=&qu...

how do I stop word from making decisions for me?
I do not want word to make a list just because I type in a number at the start of a sentence. I do not want word to indent my work for me because I tab each sentence at the start. How do I stop this monster from deciding what I want it to do I am in charge of the word processor but this software seems to think that it is and it is driving me crazy. http://word.mvps.org/FAQs/Formatting/TameAutoFormat.htm -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gma...

How to Make Table query create a Yes/No field
I have a query which will make a table which will then be used in a form for some data entry/manipulation. I want to put a couple of Yes/No fields in that table, filled with "no." I can set the property of the field in the design grid to yes/no. The field itself, I have tried: Approved:no Approved:"no" Approved: 0 The first generates an error, The second generates a text field, the third generates a number field. How do I generate a Yes/No field? consider; instead of a MakeTable query use an AppendQuery; you can then premake your table with the field property be...

Making personal stationary for e-mail
Wizzard will not accept any name I put in. Therefore I can't 'finish' making a personal stationary. ...