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
1922 Views

Similar Articles

[PageSpeed] 18

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 (1777)
11/9/2009 11:35:22 AM
Reply:

Similar Artilces:

Making my website "Firefox Friendly"
Having uploaded my Publisher website, I'm hearing from friends that only the first page is visable in Firefox. The links to subsequent pages don't work. How can I fix this? Thanks in advance! In the future, please post web related questions in the web group at microsoft.public.publisher.webdesign and we will try to help you there. In the meantime go to Tools > Options > Web tab and uncheck "Rely on VML..." (Pub 2003) and "Allow PNG...", and do not use a master page in a Publisher web publication. DavidF "VictorySpeedway" <TeachSeek@gma...

Identifying all Namespace / Prefixes when reading an XML
How do I identify all of the namespace / prefix pairs associated with an XML document I am reading? Thanks for any help. Paul PaulF wrote: > How do I identify all of the namespace / prefix pairs associated with an XML > document I am reading? XPath has a namespace axis you could have your code walk. It depends on how you read your XML document, with Xml(Text)Reader you do not have XPath support. With XPathDocument or XmlDocument you do. XPath expression is //namespace::* or (with duplicates removed) //namespace::*[not(. = ../../namespace::*] Note that the prefix xml is a...

update installation fails
After downloading the outlook 2003 updates (KB828041,KB83233) the installation program fails to install the updates. I have disabled the virus scaner and firewall. Have you tried saving the downloads to you hard drive and then executing them rather than downloading them from Office Update? That worked for me when I had similar problems. This probably doesn't apply to you, but folks trying to update pirated copies of Office 2003 will find the updates will not work for them. Russ Coover "srk" <anonymous@discussions.microsoft.com> wrote in message news:324301c3c5b6$b5c...

How do I make Saturday and Sunday full frame in Oulook 2003?
Saturday and Sunday are my busiest days. There is not enough room for my appointments in the monthly view. How can I make them full frame instead of half frame? Right click on an empty spot in the Calendar and choose Other Settings... Here disable the option for "Compress weekends days" -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-outlook.com/ Outlook FAQ, HowTo, Downloads, Add-Ins and more http://www.msoutlook.info/ Real World Questions, Real World Answers ----- "Weekender" <Weekender@discussi...

Newbie Xpath Question #2
Hi everyone, i have a quesiton regarding XML/Xpath i have a XML document that has let say the following structure <cases> <case> <num>1<num> <detective> <name>John</name> <lastname>Smith</lastname> <detective> </case> <case> <num>2<num> <detective> <name>Roger</name> <lastname>Wilco</lastname> <detective> </case> </cases> I want to know, what would be the most "by the ...

how do i create subset and union in XPath Query
Hi Friends, I need a XPath query, whcih ll return me subset of data.... check below xml stream <label id="MyExpenseDetails_lbl" xlink:role="terseLabel">Short Expense Details</label> <label id="MyExpenseDetails_lbl" xlink:role="displayLabel">Expense Details</label> <label id="InternalExpense_lbl" xlink:role="displayLabel">Internal Expense</label> <label id="ExternalExpense_lbl" xlink:role="terseLabel">Short External Expense</label> See above xml data having 4 label ...

Outlook 2007, Cached Mode, name resolution fails
I'm having a similar problem as discussed here: http://groups.google.com/group/microsoft.public.outlook/browse_thread/thread/1f521281a6a07fa6/01bdb551c91c034d?lnk=gst&q=cached+mode&rnum=16#01bdb551c91c034d With Outlook 2007 the key for Cached Mode no longer exists. I'm also receiving the following error when I do a check names when I type portions of users display names: "Too many names have been found in the directory service or the server has exceeded its time limit for searching. Type more letteres of the name and try again." I've checked and our OAL is bei...

Macros failing in different language versions of Word
My company wants to standardize on templates across several countries - we have offices in many countries, but for simplicity I will just talk about UK and Sweden. My problem is that some features in the English version of Word do not work in the Swedish version of Word. For example, StylRef. I use StyleRef in the header margin to refer to "Heading 1" style. The problem is that it is not called "Heading 1" in the Swedish version of Word. It is called "Rubrik 1", which translates back to "Heading 1" of course. In the UK we use many macro...

make an excel worksheet (sheet 2) open w/ the cursor located in t.
I have an excel worksheet with three sheets. Sheets 2 and 3 are locked so that entries can be made in only certain cells. Sheet 3 is linked to sheet 2 so that when an entry is made on sheet 2, the entry appears on sheet 3 in the corresponding cell. I would like sheet 3 to open in the cell the last entry was made (which is the corresponding cell on sheet 2 because sheet 3 is completly locked except for the link to sheet 2) Is there a simple way to perform this task? ...

count passed or failed
im having a problem getting the correct formula for this one. i used =IF((DATA!$G$2:$G$5000-DATA!$F$2:$F$5000)=(DATA!$K$2:$K$5000-DATA!$J$2:$J$5000),"Passed","Failed") and =COUNTIF(DATA!$L$2:$L$5000, "name@email.com") and it gave me the desired output. but the problem is, i have to get the total number of passed and failed for each person in my team. i can't seem to find the exact formula to combine those conditions. please help me, thanks! Neri, =SUMPRODUCT(((DATA!$G$2:$G$5000-DATA!$F$2:$F$5000)= (DATA!$K$2:$K$5000-DATA!$J$2:$J$5000)) *(DATA!$L$2:$L$...

Make cells match
In sheet 1 I am asking several Yes/No questions. I have a cell after the Yes and after the NO that I want the value "X" entered into. It will of course either be one or the other. I then want that "X" to show up in sheet 2, which is a form I want filled in with the data from sheet 1. If I simply do A1 = C1 and B1 = C2 I get a value of "0" in the cell they didn't put an "X" in. So if the put an "X" in the Yes cell in sheet 1 then an "X" shows up in the Yes cell in sheet 2, BUT since they didn't put anything in the No cell...

I am making a charts with weird X-values for my Ecology cl\
i am making a chart with weird X-values. Instead of single, whole numbers, I need each value to be as follows: 1-2, 3-5, 6-10, 11-15, etc. Please help me!! My chart keeps going to whole numbers instead and its been driving me crazy for days! What chart type are you using? If you want your X-axis to be category labels, rather than actual numbers, you may find that a line chart (or one of the other chart types) is more suitable than an XY (scatter) chart, if the latter is what you are currently trying. -- David Biddulph "Holly" <Holly@discussions.microsoft.com> wro...

Operation failed when deleting messages
We have an Outlook 2003 user who receives the following error: "the operation failed" anytime a he tries to delete a message. No other information is given with the error. We are running Exchange 2003. He can log in through the outlook web interface and delete messages. Its possible that this began occurring after a power outage. Any suggestions? signaturefactory@signaturefactory.com wrote: >We have an Outlook 2003 user who receives the following error: "the >operation failed" anytime a he tries to delete a message. No other >information is given with th...

Make values stay put in established record & reset in new record?
I'm having a problem making the values on a form reset to $0.00 when I go to a new record. Some more info would help us to help you. How are you going to a new record? A button you put on the form? the new record button on the navigation buttons at bottom left of form? What does the value show instead of $0.00 when you go to a new record? Are there any other values that don't reset when you go to a new record? Jeanette Cunningham "Peg" <Peg@discussions.microsoft.com> wrote in message news:B39F82B9-43E2-4B9A-8F9B-C64B46240857@microsoft.com... > I'm having a...

How do I make a nomogram in Excel?
I wanna make a nomogram in excel, can sombebody help me?? jezuz - When I paste "nomogram in Excel" into Google, I get 527 hits. Have you looked at any of those sources? - Mike www.mikemiddleton.com "jezuz" <jezuz@discussions.microsoft.com> wrote in message news:A23AF947-8FE7-44BC-ACF1-129CA5672B76@microsoft.com... >I wanna make a nomogram in excel, can sombebody help me?? ...

How do I make this load and save faster?
I have an Excel 2002 SP3 Worksheet that extends to cell J:210. This uses data validation in slightly less than a third of the cells and sums the validated data in approx 17 rows. This creates a 288 KB file which is slow to open and save on my WIN XP Home Pentium 4 CPU 3.00GHz, 1.00 GB RAM PC. See 'example.xls' at http://www.btinternet.com/~chris.a.mitchell/oddsandsods/ This worksheet needs to be repeated several times in a workbook which becomes very slow to open and save. I have disabled Add-Ins to improve Excel opening times, but still this Worksheet takes a long time ...

What is the step-by-step procedure for making a data list?
I've read and re-read how to do datalists, but I cannot get the hang of how to make one and apply it. I need a simple tutorial in how to make one, from A to Z. I want to call in items that have cost associated with them instead of typing them each and every time. Any GOOD help will be greatly appreciated. Try Debra's nice coverage on VLOOKUP at her: http://www.contextures.com/xlFunctions02.html -- Rgds Max xl 97 --- GMT+8, 1� 22' N 103� 45' E xdemechanik <at>yahoo<dot>com ---- "Bobgolfs56" <Bobgolfs56@discussions.microsoft.com> wrote in me...

Microsoft offfice system 2007, Update instalation failed
Error Code: 0x80070663 Update for the 2007 Microsoft Office System (KB981715) Security Update for the 2007 Microsoft Office System (KB982312) Security Update for the 2007 Microsoft Office System (KB982331) I m trying to install this three updates but it's always says instalation failed. I tried in automatic update and in internet explorer. neither of these worked. my computer always says new updates found. my laptop is running on XP MEDIA CENTER EDITION. I am running MS office 2007. im getting the same messages and the same problem. i keep hiding them and they keep coming ...

Please provide me some instructions about ..inf file used to make a cab file
I've made a "big" AcitveX control, it uses a lot of .dll files In order to make a cab file ,I have to make a .inf file first. I've read related files in MSDN .But they are too short. I need a complete .inf file. Please help me. Thank u very much!!! http://msdn.microsoft.com/library/default.asp?url=/library/en-us/install/hh/install/create-inf_4l47.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/install/hh/install/inf-format_7soi.asp Have you read this? ...

Making a search form
I need help writting code behind a search form i made. It has combo boxes of different things you can search by account number, Date etc what is the code behind the button that will make another form pop up with the info i asked to search by in it? iLevy wrote: >I need help writting code behind a search form i made. >It has combo boxes of different things you can search by account number, >Date etc what is the code behind the button that will make another form pop >up with the info i asked to search by in it? Here's a article on that topic: http://allenbrowne.com/ser-...

Outlook (2004) Google quick search has started failing
When I search for a term in my Outlook using Google quick search, the result is "search failed" or "0 emails" it looks like i needed to re- index, which I have attempted to do, but the email and file counts during reindexing are stuck at 0. No files are being indexed I guess. This problem is recent, it may have started when I changed to a newer computer, but I am not so sure, I think it was working at first. Anyone got any ideas? <williamheyn@gmail.com> wrote in message news:1187123256.256985.314400@l22g2000prc.googlegroups.com... > When I search for a term ...

Create Mailbox Exchange Task Fails
W2K3 AD domain, W2K3SP1 DC's, EX2K3 on W2K3SP1 member servers. Had an existing user in AD that I wish to create a mailbox for, so used Exchange Tasks - Create Mailbox. That failed, so I asked for a detailed report: <?xml version="1.0" encoding="unicode" ?> - <taskWizardRun taskName="Create Mailbox" dcName="DC1" buildNumber="7638" runningAs=administrator@DOMAIN.COM> <timespan startTime="2006-08-28 12:20:08.216" milliseconds="1297" /> - <createMailbox> <database>/dc=com/dc=domain/cn=C...

xpath
Hi, I'm trying to get the @order attribute of the <WI> element for the LAST WI element for the Board element as specified. I've tried every combination I can think of, but I'm not getting any node returned. I'm using xpathvisualizer to check it. //Station[@name="Station1"]/WI[Boards/Board[@sn="583230"][@finish]][last()]/@order I've also tried parens in several place including: (get various expected token errors) //Station[@name="Station1"]/(WI[Boards/Board[@sn="583230"][@finish])[last()]]/@order Thanks, Kathy xpath is fun, ...

Template Creation has Failed
I am try to make a template for an install on a new computer. We have just updated to SP2 so i figured I would make a new template install for the newer computers we bring into the office. The problem I am having is that it keeps failing. I've tried using the compressed method, the non-compressed method, but they both fail. Anyone have any suggestions? The error message i am getting is: An error was encountered while attempting to create the archive. Template creation has failed. C:\GPCD1\AdProd\CabArc\cabarc.exe -r -p -P "GreatPlains80\\" -m NONE N "C:\New Folder...

Calculating cells on workbook_open failing without message
I have to refresh 2 cells when the workbook is opened. I have an On Error surrounding my code that gets run. The err.Description is always empty yet my error message box is being shown and my cells don't open. Each of the two cells are named - pdate and fdate. They call a function which is located in an addin. I can manually update these by clicking F2 and pressing enter in each cell. Any idea what to look at? Once person said that something else that depends on these cells may be failing and the error just isn't being displayed. Thanks, Joe Hello, When m...