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

Similar Articles

[PageSpeed] 12

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:

Fail when registering MS CRM 3.0
Hi, I've little problem when try to register MS CRM 3.0. It always said something like this : The wizard requires an Internet connection to complete registration. Activate your Internet connection if it is disabled. If you do not have an Internet connection, contact Microsoft Business Solutions Support at 1-800-456-0025 to complete registration. Funny thing is I have internet connection, and I already remove all firewall settings. Can any bode help me, since I only have 4 days remaining. Rgds, Hi You just need to make sure the State field is completed - its not shown as comp...

Creating XML element from XPath
Hi, Is it possible to automatically create an XML element given an XPath query? For example I have the following XML doc: <topic> <title>Hi this is the title</title> <description>This is a simple desc</description> </topic> Now say I have an XPath query '/topic/age' which will return a null node if I run it against the above XML doc. Now is there an easy way to automatically create the age node if it doesn't exist? Or do I need to do manual parsing and create the node manually? For the above example probably you'll think that ...

How do I make a water mark for an existing text page in publisher
When I insert a picture on my document then properties for watermark and arange to send to background the water mark disappears. and if I try other ways then my text on my original document dissappears. Put your watermark on the Master Page (ctrl+m). Any picture can become a watermark if you use the wash out feature. -- Mary Sauer http://msauer.mvps.org/ "jimmyy" <jimmyy@discussions.microsoft.com> wrote in message news:8D0FCE3D-0A94-4908-BC33-2D9DA59DF614@microsoft.com... > When I insert a picture on my document then properties for watermark and > arange to send ...

How do I make my tool bar icons larger?
I am just trying to enlarge my tool bar icons, i.e., the home, etc. Maybe there are some Accessibility options that can help (look in Control Panel)? If not, reducing the screen resolution is the only way. -- Stefan Blom Microsoft Word MVP "Debbie T." <DebbieT@discussions.microsoft.com> wrote in message news:6D0852D8-DAD1-49EB-A08B-CA4D3E1BB293@microsoft.com... >I am just trying to enlarge my tool bar icons, i.e., the home, etc. > > "Debbie T." <DebbieT@discussions.microsoft.com> wrote in message news:6D0852D8-DAD1-49EB-...

Is there a way to make a staircase text effect?
Is there a way to create a string of letters that will remain erect when the object they are part of is rotated? I want to create a staircase effect where the letters look like they are sitting on the steps of a staircase and be able to alter how steep the staircase is and have the letters remain vertical. Thanks -- Email: Usenet-20031220 at spamex.com (11/09/04) Nothing built-in per se. You'd have to create separate shapes that belong to a group, and do some ShapeSheet programming. The shape's could then "anti-rotate" relative to the group (Angle = - GroupSheet!Angle...

Make Userform Caption equal textbox contents
How does one make a Userform title bar caption Equal the contents of Textbox1? Can anyone help? Thanks, Roger You can try Private Sub TextBox1_Change() UserForm1.Caption = TextBox1.Text End Sub or you can use Textbox1_Exit event... -- Jacob "Roger on Excel" wrote: > How does one make a Userform title bar caption Equal the contents of Textbox1? > > Can anyone help? > > Thanks, > > Roger Thanks Jacob - works nicely Roger "Jacob Skaria" wrote: > You can try > > Private Sub TextBox1_Change() ...

Make Day CAPS In Custom Date Format
I've got a cell formatted thus: hh:mm ddd dd.mm.yy which returns 19:20 Thu 25.02.10. I want 19:20 THU 25.02.10, ie the day in caps. You need to use the Upper function, as in: =UPPER(TEXT(A1,"hh:mm ddd dd.mm.yy")) Regards, Fred "robzrob" <robzrob@hotmail.com> wrote in message news:15c33695-2b53-4d8f-8173-1aa6f178b739@g28g2000yqh.googlegroups.com... > I've got a cell formatted thus: hh:mm ddd dd.mm.yy which returns 19:20 > Thu 25.02.10. I want 19:20 THU 25.02.10, ie the day in caps. I don't think you'll be able to do it in for...

Send Mail failed to send message
Outlook works fine when sending and receiving email via Outlook. However when I use another program (e.e. MS Paint) and click Send, I get an immediate error message, "Send Mail failed to send message". I have checked the registry, Internet options, and Outlook and all locations indicate that Outlook is the default mail program. I am running Office 2003, XP Pro. I do have Mozilla Thunderbird installed and it operates as well. It is NOT the default mail program. Thanks for any suggestions. ...

Is it possible to make a box and whisker plot (box plot) in Excel.
I can't figure out a way to do it using just the Chart Wizard. Hi, Maybe Jon's page(s) on the subject may help. http://peltiertech.com/Excel/Charts/BoxWhisker.html Cheers Andy -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info "rfsp" <rfsp@discussions.microsoft.com> wrote in message news:49729C95-E66F-4FE4-96AD-B64B88ECD6B9@microsoft.com... >I can't figure out a way to do it using just the Chart Wizard. Now that I've joined, I see this was just answered a couple of days ago. Sorry for the repeat question. Please ignore. "rfsp"...

How do I make a photo collage in Publisher 2003?
I have Publisher 2003 and I want to make a photo collage. Tabitha wrote: > I have Publisher 2003 and I want to make a photo collage. ================================================ Just import your photos by going to...Insert / Picture / From File. Resize the photos by dragging the corner handles. Reposition the photos by dragging with the 4 way arrow or nudging with the arrow keys. Rotate partially (for effect) by dragging the Rotate (green ball) handle. Also you might consider downloading and instralling the freeware Picasa 3...it has several options for creating collages. Just sele...

GDI is a "Top 50" Inc500 Listed Company...Are You Tired of Working Hard to Make Someone Else Rich?
Dear Friends, Are You Tired of Working Hard to Make Someone Else Rich? This Inc500 listed company is giving away money... This company is going to set me up for life and it can do the same for you. Read about how 1000's of real people worldwide who are building their own "Income for Life"=99 http://freedom.ws/helenmoonlight/show_dvd Watch the video until the end - make sure your speakers are on before you click http://www.website.ws/helenmoonlight I am confident that you will be impressed with what you see and hear. http://www.my.ws/helenmoonligh...

Back-to-Back DoCmd.OpenReport fails if Printer Offline
I have discovered that this fails: private sub DoListAndReceipt() DoCmd.OpenReport ... DoCmd.OpenReport ... end sub when my Printer is Offline. The first OpenReport executes and makes it to the Printer Queue. The second OpenReport does not execute at all. Execution falls-thru to the "end sub". Cancelling the first report in the queue does no good. I have traced, trapped, etc., but to no avail. The printer offline aborts the second DoCmd.OpenReport. The application is in Access 2003 with a 2000 mdb format. Does anyone have a "sol...

Popup menu fails to notify ONE type of owner but not another
I have a problem with an owner-drawn popup menu class failing to notify its owner window when the user clicks on items in it. The strange thing is that it only fails to notify SOME owner but not others. If I supply a different owner for the TrackPopupMenu calls, it works fine. Call this class, "CPopup" To illustrate: 1. I have a CWnd derivative called CMyCtl. It has a button on it 2. The user presses the button and my control has a handler. 3. In the handler I instantiate a CPopup object and call TrackPopupMenu to bring up the menu.. The menu pops up just fine. void C...

How to make 1 change to many contacts?
I was making a "common change" to multiple contacts using the directions provided by Microsoft's site. I sorted the contacts by category, selected the grouping bar for the category I wanted to change, and dragged the contacts to the category I wanted it to become. Outlook is supposed to automatically apply the change to all of the items in the old category. It gave the contacts 2 categories. I will still have to open 300 contacts individually to get rid of the old category. Is there another way to make a the same change to multiple contacts? Veronica wrote: > I wa...

The connection to the server has failed. ... emails not sending.
Hi, My granparents recently got a laptop and set up their Outlook Express. Up until recently they were able to send and receive emails, and now they can only receive. The following message appears when they try to send an email .. The connection to the server has failed. Account: 'mail.tpg.com.au', Server: 'mail.tpg.com.au', Protocol: SMTP, Port: 25, Secure(SSL): No, Socket Error: 10051, Error Number: 0x800CCC0E I've having a look with no success (i'm their grandaughter) Does anyone know how to fix this? Thanks, Rachel Have you checked you...

Setup.exe fails to lauch
Hi all, I'm trying to install the Collections Module. The demo shield appears, but the setup.exe for CM fails to launch. Setup.exe is in task manager, but there isn't a dialog box appearing to install the application. This happens with other installs too (ie SDK, Fixed Assets, etc..). Any ideas how to get this goin again? It's obviously a problem with InstallShield. Thanks. -jeff Hi You should be using CDSetup.exe and install Additional module. Also check that you have full local admin rights to the workstation James "Jeff" <Jeff@discussions.microsoft....

how to make subsite to offline or to maintanance?
I have sitecollection where I should make subsite is for maintanance. It means when other than Administrator click on Subsite or browse with subsite url it should display message , THIS SITE FOR MAINTANANCE. And it should maintan from administration I don't believe this can be an issue in Windows XP. Perhaps you will ask your web host for assistance. Janardhan Ch wrote: > I have sitecollection where I should make subsite is for maintanance. It > means when other than Administrator click on Subsite or browse with subsite > url it should display message , THIS SIT...

Cannot make any changs on server
Every time I try and make a change, or publish something on my test server, I receive this error message "An error has occurred. For more information contact your system administrator" I have set the web config file to give more details on errors, but it does not give anything more than this for the error. I cannot find any problems in the event logs of the servers. I have even restarted the, to no avail. Does anyone know what could suddently cause this problem? Hi Saira, In the web.config, did you change <add key="DevErrors" value="Off" /> from &...

how can i make a in-process report that can be accessed by severa.
i need to set up an in-process report that can be accessed by several users at once, in which every user can input data without shutting down the workbooks on the remaining computer so that the one user can do his inputting. Hi you could use 'Tools - share workbook' BUT: - several functions are then no longer available (see Excêl's help for details' - IMHO Excel is NOT designed for multi-user access. Use a database application instead -- Regards Frank Kabel Frankfurt, Germany "tim" <tim@discussions.microsoft.com> schrieb im Newsbeitrag news:E5B2A371-4...

can I make today() static in excel. I need a date formula that ca.
I need a date formula that calculates a date when a cell is populated and then is static. I need to know the date a cell is populated. ...

SQL Express Install failed installing CRM 4.0 Outlook Client w/off
I have run into this problem a couple times on different laptops. When I try to install the CRM 4.0 Outlook Client, with Offline Access. During the installation process, when it get to the point where it tries to install SQL Server Express, the installation fails. We never did a deployment of CRM3.0, so it is not an upgrade issues, as most of these systems, never had the 3.0 client installed on them. Any ideas where to go from here? Hi, Try to download and install the sql express edition from internet . If it doesnt get installed then it will show you the detailed error . There was pro...

POP3 Connector Failed Folder?
Hi, My exchange2003 pop3 connector says it has mail in a failed mail folder....but I have no idea where it is?? I'm sure it's not the administrators? Thanks. "Adam" <anonymous@discussions.microsoft.com> wrote: >My exchange2003 pop3 connector says it has mail in a >failed mail folder....but I have no idea where it is?? >I'm sure it's not the administrators? That POP3 connector is specific to SBS, it's not an Exchange tool. If nobody answers this in this newsgroup you'll probably get a better/faster answer in one og the SBS newsgroups. ...

Make client area of frame view a certain (fixed) size (AdjustWindowRectEx problem)
Hello, I'm trying to port a program written in raw Win32 (so I can ask for help regarding it here) to MFC and I've run into a problem. The program is supposed to be fixed in size and the client area must be of size 400 * 400. The Win32-program uses AdjustWindowRectEx() to calculate the needed width and height that should be passed to CreateWindow() when the main window (which is, in fact, the only window in the program) is created and that works fine. My MFC version is an SDI-program without doc/view support but the frame window does have a view. So I tried to call ::AdjustWind...

How do I make landline phone calls via Outlook 2007?
Outlook 2007 has the facility to dial the phone number of an Outlook Contact but I presume that this requires some hardware ( a phone modem?). Can anyone please explain, or point me to a URL that explains, how I can make the facility work? I sense that I will need to know:- 1. What hardware I will need. 2. Where I can buy that hardware. 3. Whether I will need software additional to Outlook 2007 Any help would be gratefully received. Outlook has no such facility. You must provide a voice modem and the software to support it to dial and talk from your PC. Whether that third party s...

Making sure a replica of another node is not saved in the xml document
Hi, How do I iterate through the nodes of an xml file to check if the newly added node is a replica of another node(incl. innertext and each element of the node and values thereof) ? If there newly added node is a copy of another node I would then delete the new node and save the xml file. All this would be done from the click event of a button in a webform. What is a good way of achieving the above? A code sample would be great. Thanks a lot Anita, Yould run an XPath expression against the document before you insert a new element. The most generic case would be an XPath like this: //*...