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

Similar Articles

[PageSpeed] 3

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:

Why do Forex Traders Fail?
The high rate of failure for a new trader can be related to the six major obstacles that a trader faces, which are summarised as follows - * Poor Skills * Lack of adequate capital * Setting unrealistic targets and goals * Lack of Patience * Lack of discipline * High risk aversion. If we look at the list, it becomes apparent that the failure is as a result of trading without having in place a proper Trading System and a Trading Plan- One that includes mind training, quality Forex education and strategies and sound money management rules. So what are the Characteristic...

Publisher is making me crazy!
I have been trying to create a flyer for a small business. Using the Wizard, I am having a problem with the text. I need 8 text boxes. The Wizard only allows me to use 5, and several of those are not the sizes I need. One is for a tag line, which I don't need, I need one that I can enlagre enough to put in a list. When I try that, the list starts at the bottom, and will not line up with the type on the other side of the page! I have been working on this flyer for 3 weeks, with NO luck. Why can't I add my own text boxes? And if I CAN add text boxes, please tell me how ...

Arcserve 11.5 failed to backup two mailboxes out of 103
We use ArcServe 11.5 to do a document level backup of our Exchange 2003 mailboxes. When the application ran for the first time last night on the production server, after testing on a test server, the notification I recieved was that the backup job was incomplete. It failed to backup two mailboxes out of 103. How can I determine which mailboxes were not backed up and more importantly, why they were not backed up. I am not sure if this is an Exchange 2003 issue or an ArcServe issue. My inclination is that it is an Exchange 2003 issue because it did successfully back up the other 1...

Help! Workspace creation failed and PS2007 still thinks it exists although I can't see it in PWA
I had a workstation creation fail on an "XYZ" project. When I try to re-publish using a different template (which I know works), it says the workspace already exists. Problem is I can't see it in the Project Workspaces area of PWA, nor from the Sites area of PWA, nor from the Project Workspaces area of the Server Settings page, nor from the Sites and Workspaces are of the Site Settings page (of PWA). I've got to figure out what about the newly provisioned template it doesn't like (I've since then changed to the previous version), but first I need to get r...

How do I make an image more or less transparent in Microsoft Publi
Please Help?! Select your image, color icon, select washout. For objects you fill yourself, such as autoshapes, you can set the transparency. Click fill, fill effects. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Plattner Orthopedic" <Plattner Orthopedic@discussions.microsoft.com> wrote in message news:8ACFF04D-B97A-437E-B294-F60378CFDB62@microsoft.com... > Please Help?! Which version of Publisher are you using. Sorry we do not know as our crystal balls failed from overwork "Plattner Orthopedic"...

CRM 3.0 installation failed on reporting services installation last step
CRM 3.0 installation failed again at last step of installing reporting services. it only says unexpected error occured and error code is 25616. is there a recommended way of CRm 3.0 install? i meant to say that is it preffered to install reporting service seperatly ??? now what i should do with the installation? should i need to prepare the machine again for re-installation? this installation is not helpful as it did not tell any detail error and it says every thing ok on Pre req verification. One further thing i encountered after 25616 error that it displayed me a Message to Retry Abort or ...

Make a formula
Is it possible with Excel 2000 to automatically make a list of all the formulas you are using in your spreadsheet to print them. Thanks...Steve -- Steven E ----------------------------------------------------------------------- Steven E.'s Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1512 View this thread: http://www.excelforum.com/showthread.php?threadid=26758 This subroutine makes a new sheet (Formulas in Sheen N) in which all formulas are listed together with cell reference and value. Not mine-own but I have lost the reference to the author but I thank h...

Resolution to CRM 1.2 database export failed error during 1.2 to 3.0 upgrade
After struggling with this error working with MS Support and receiving no resolution, we were able to solve the problem through KB article 916924 (see below). Why MS Support did not point us to this in the first place is quite frustrating, so hopefully this will help others! CAUSE Cause 1 This problem occurs because there are saved queries in the Microsoft CRM 1.2 databases that are malformed. This problem usually occurs because a third-party product is not completely removed from the Microsoft CRM databases before you upgrade to Microsoft Dynamics CRM 3.0. Cause 2 This problem occurs if th...

An open on table 'ME_Direct_Deposit_MSTR' failed accessing sql data.
Hi.. We are on Dynamics GP 9.0 and we recently updated our GP with 'Advanced Human Resource and Payroll suite 9.0'. The update on the server and client computers went through good but when one of our user is trying to print a payables check its giving the following error message. "An open on table 'ME_Direct_Deposit_MSTR' failed accessing sql data." We initialized the database for all our companies by logging in as SA and accessing all the companies on server as well as client computers. Any idea what could have gone wrong? Any help on this one will be much appre...

can I make a empty priv1.edb database in Ech 2003 ??
need help new can I make a empty priv1.edb database in Ech 2003 ?? THANKS Sure you "can", but the question is why? If you want to create a new empty database, then you would dismount the Mailbox store, then delete, move or rename the existing files. Next, simply re-mount the Mailbox store and you will be presented with a message box indicating that new blank databases will be created and do you want to proceed. That's really all there is to it. If you have any mail in the old databases, I'd seriously recommend that you either rename or move them instead of dele...

what makes the unread emails are not marked as unread....
We have one exch2k and Outlook 2002 clients. Sometimes new incoming unread emails are not marked as unread in Outlook. Why is that? Thanks Calvin On Wed, 20 Apr 2005 08:17:41 -1000, PinkCrib <webmaster@pinkcrib.com> wrote: > We have one exch2k and Outlook 2002 clients. Sometimes new incoming > unread > emails are not marked as unread in Outlook. Why is that? > Thanks > > Calvin So you're saying that the messages are automatically being marked as read somehow? Do you have a Rule running that is marking them as read? -- -Ben- Ben M. Schorr, MVP-OneNot...

DATEVALUE("10/30/2009") Fails with #VALUE! Error
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Hello, <br> I need to manipulate some date/time strings that I'm importing from an external source. The strings look like this: <br><br>10/30/2009 3:19:08 PM <br><br>I need to separate date &amp; time, and use subtotals etc. on change of date &amp; change of hour. <br><br>I thought the best thing would be to separately extract the date and time, then use DATEVALUE() on the date string so I can format it as yyyy-mm-dd and do calculations. <br><br>...

Namespacemanager adding default namespace
Hi I'm trying to read xml file with namespacemanager; it seems that it adds up a namespace if there is none; How can avoid this? so <ID>00589</ID> becomes <Id xmlns=\"x-schema:#Schema1\">00589</Id> Thanks Vishy Vishy wrote: > I'm trying to read xml file with namespacemanager; it seems that it > adds up a namespace if there is none; How can avoid this? > so <ID>00589</ID> becomes > <Id xmlns=\"x-schema:#Schema1\">00589</Id> Namespacemanager can't add namespace, it only helps resolving namespac...

how do i change or make this macro??? pictures and code included
i need to either make this from scratch or change it to suit my needs. Firstly a link to the template it is from http://www.exinfm.com/excel%20files/FY2000WhatIf.xls the code is Sub projection() Dim revgrowth As Single, costpercent As Single, smgrowth As Single devgrowth As Single, gagrowth As Single Dim intincome As Integer, noncontitems As Integer, otherexps A Integer Dim taxrate As Single, avgshares As Integer 'dialog box gets displayed With DialogSheets("dialog3") If .Show = False Then Exit Sub End If revgrowth = .EditBoxes(1).Text costpercent = .EditBoxes(2).Text smgrow...

get list of used namespaces
Hi all, I load an xml file into XmlDocument object and would like to get a list of namespaces used in the file. How can I get a list of namespaces used in xml file? Thanks. helpful sql wrote: > I load an xml file into XmlDocument object and would like to get a list > of namespaces used in the file. How can I get a list of namespaces used in > xml file? XPath has a namespace axis for namespace nodes which are in scope for a given element node, here is an example using an XPath expression with SelectNodes to output all namespace nodes (those explictly given and th...

SBS2003 Backup Failing
Hi I have been away for a week and come back to our server backups failing. Below is a copy of the log for last nights backup. Anyone got any ideas way it would start to fail when nothing has changed? 6/09/2010 11:00 PM ------------------------------- Date: 6/09/2010 Time: 11:00 PM User: SYSTEM ------------------------------- Backup Runner started. Launching NTBackup: ntbackup.exe backup "@C:\Program Files\Microsoft Windows Small Business Server\Backup\Small Business Backup Script.bks" /d "SBS Backup created on 6/09/2010 at 11:00 PM" /v:yes /r:no /r...

track changes toolbar always pops up: make it stop!
this is one of those small things about word that drives me up a wall: whenever i turn track changes on and hit ok in the dialog box, a track changes toolbar suddenly appears. i don't want it there. i just want to edit what looks like a normal document with word tracking changes in the background. is there any way to make this toolbar stop appearing automatically? There's no provision in the program -- the bar is deemed necessary for more users than not. Depending on your version of Word you may be able to come up with a programmatic solution. Regards |:>) Bob Jones ...

make journal entry for a contact that is open
For managing my business contacts, I like Outlook 2003 functionality better than 2007. How would I safely go about going back to 2003 (I have the cd) without loosing my data. I recently bought and upgraded to Outlook 2007 and don't like it as well. Back up the PST, uninstall outlook 2007, reboot, install 2003. Note that if you are using Office, you'll lose some functionally if the versions don't match. -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com/ Outlook Tips by ...

Prefixed namespaces and Xpath
I have come across what seems like a failing in the .Net XML classes. Many people have posted requesting how to write an XPath query with namespace prefixes that works. The solution shown in all the posts I have seen is of the form: --------------------------------------------- XmlDocument doc = new XmlDocument(); doc.Load(@"c:\foobar.xml"); XmlNamepaceManager nmMgr = newNamespaceManager(doc); nmMgr.AddNamespace("abc", "www.my.uri"); --------------------------------------------- Now you can call SelectSingleNode and SelectNodes with an XPath query that contains...

in a macro how to make a part of the formula a variable
I am trying to copy a cell from one file into another file in a macro. There are hundreds of files all linking to the same cell so I thought I would set the formula up so that is has a variable for the filename but I can't figure out the syntax. The formula should link to cell $r$16 in worksheet "monthly" in the changing file name and the variable I used for the changing file name is budget_file. The following didn't work. Can someone tell me how to do this? ActiveCell.FormulaR1C1 = "=" & budget_file & 'monthly'!$r$16&qu...

GP 10 fails to store menu toolbar locations
GP version 10.00.1237 Standard The menu/toolbar fails to keep the menu options and buttons in the location I put them in and then lock the toolbars. Sometimes they work, but other times if I work on other programs while GP is starting up after selecting my company to work in when I return to GP the menu is all rearranged, but is still locked. I searched and there was one question directly relating to this and another that references locking the "toolbar", but neither really address the issue or offer a solution. Does anybody from Microsoft have a solution to this problem or...

Field Service Installation Failed in GP 8 with Arabic Collation
Hi All, I unable to install the databse schema to any of the database due to field service does not install on Arabic Collation. Anybody has solution. Regards Akber ...

can you help by make link with tow worksheet
I'm looking to make link with tow worksheet more clearly: i made equation in cells worksheet -1 a1 + a2 : print result in cell A1 in worksheet -2 and thankyou for help -- nader ------------------------------------------------------------------------ nader's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=10881 View this thread: http://www.excelforum.com/showthread.php?threadid=383968 Type in: =Sheet1!A1+Sheet1!A2 Place in Cell A1 of worksheet -2. Or, place the cursor in the desired cell of worksheet - 2 and click "=". Then click on the wo...

how can i print cards on a single page and edit side two and make.
This isn't. Post your message in this bit, describe it in the top bit. That way, you see the entire message rather than just the start. -- Ed Bennett - MVP Microsoft Publisher ...

HOW TO: Make Excel think there have been no changes, without savin
Hi TWIMC How can I make Excel think that no changes have been made without saving the workbook. Something like in Access on a FORM where you can set Me.Dirty = False? TIA KM One way: ActiveWorkbook.Saved = True In article <D0EA4B60-1BB5-4B4B-BCD2-D9491D6B3D14@microsoft.com>, Kevin McCartney <KevinMcCartney@discussions.microsoft.com> wrote: > Hi TWIMC > > How can I make Excel think that no changes have been made without saving the > workbook. Something like in Access on a FORM where you can set Me.Dirty = > False? > > TIA > KM ...