473,802 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPathNavigator not working when schema used

Obe
PLEASE HELP!

I'm writing a function to populate DropDownLists from and xml file. I
am having a problem getting my XPathNavigator to select any nodes when
I attach a schema to my xml document.

Xml Doc: Dropdown.xml
XML Schema: Dropdown.xsd

Here is my XML Document...

<?xml version="1.0" encoding="utf-8" ?>
<DropDownList s xmlns="http://tempuri.org/DropDown.xsd">
<DropDownList name="DataSourc e">
<Option name="SqlServer " value="SqlServe r" />
<Option name="Oracle" value="Oracle" />
<Option name="DB2" value="DB2" />
</DropDownList>
<DropDownList name="Language" >
<Option name="ASP" value="ASP" />
<Option name="ASP.Net" value="ASP.Net" />
</DropDownList>
</DropDownLists>

....and here is my code...

private void LoadDropdownMen u(string DropDownName)
{
DropDownList GenericDropDown =
(DropDownList)F indControl(Drop DownName);

XPathDocument xpDoc = new XPathDocument(S erver.MapPath(" .") +
"\\Dropdown.xml ", XmlSpace.Preser ve);
XPathNavigator xNav = xpDoc.CreateNav igator();

XPathNodeIterat or xNode =
xNav.Select("/DropDownLists/DropDownList[@name='" + DropDownName +
"']/Option");

while(xNode.Mov eNext())
{
GenericDropDown .Items.Add(new
ListItem(xNode. Current.GetAttr ibute("name","" ),xNode.Current .GetAttribute(" value","http://tempuri.org/DropDown.xsd")) );
}
}

I don't get any nodes returned in my XPathNodeIterat or using the above
xml file and code. If I remove xmlns="http://tempuri.org/DropDown.xsd"
from my xml file, everything works perfectly.

I want to be able to use a schema with my xml file. Can someone please
explain what I am doing wrong?

Thanks in advance.
Nov 12 '05 #1
1 3222
* Obe wrote in microsoft.publi c.dotnet.xml:
I'm writing a function to populate DropDownLists from and xml file. I
am having a problem getting my XPathNavigator to select any nodes when
I attach a schema to my xml document.


You are not attaching a schema to the document, you are declaring the
namespace of the elements in your document. An XPath expression ala
//name refers to all "name" elements in no namespace, this fails if
the element is in a namespace. You need to declare a prefix for the
namespace and use that prefix in your XPath expressions. You can do
that using XmlNamespaceMan ager, see the Remarks section in e.g.

* http://msdn.microsoft.com/library/en...lecttopic2.asp

for an example and further details. The XML Namespaces FAQ might also
be helpful to resolve further issues involving namespaces,

http://www.rpbourret.com/xml/NamespacesFAQ.htm
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2202
by: Philip Rayne | last post by:
Probably a bit of a newbie question this. I have an XML file like this: <?xml version="1.0" standalone="yes"?> <AuditLogonGroup xmlns="http://tempuri.org/AuditLogon.xsd"> <AuditLogon> <Username></Username> <IPAddress></IPAddress> </AuditLogon> <AuditLogonGroup>
0
1036
by: Peter | last post by:
Hello, Thanks for reviewing my question. I would like to know if there is an easier way to regenerate your dataset in VS.NET when your database schema changes. I am frequently add or remove fields in my database and then on the VS.NET C# windows form side, I delete the dataset, the dataadapeter and the sqlconnection. Deleting just the dataset doesn't work - generating it from the dataadapeter creates a dataset with the old schema. Is...
7
5768
by: Steve Richter | last post by:
here is a simple class: public class Demo1 : System.Data.DataRow { public Demo1() { } } but it does not compile:
4
1327
by: Mike | last post by:
Hi all, I have a vb.net program running as a service that uses a network path to query a file. If System.IO.File.Exists(fpath & "\" & filename) Can anyone tell me why the above isn't working? When I place it in a none service program it works fine. Any help appreciated.
3
2312
by: jan82 | last post by:
Hi all I'm developing a website with Visual web developer in C#. Everything works fine when testing using ctrl+F5. Also, IIS runs ASP.NET pages without any problems. The problem I'm facing now is that standard ASP.NET membership is not working when not using the visual studio testing webserver. I just get the message that logging in has failed. Any suggestions?
1
1714
by: shumaila | last post by:
hello all can anybody help me???? My asp pages are not working, when i run it, it ask me for downloading?
3
1752
by: callre | last post by:
when i used javascript onchange() the error is coming "object doesnt support this property" my code is- <script type='text/javascript' language="javascript"> function change() { document.uplcsv.submit(); } </script>
0
1347
by: Nadeeka | last post by:
Hi, I wrote a Schema Validator in C#.NET. XmlTextReader R = new XmlTextReader(FileToParse); XmlValidatingReader V = new XmlValidatingReader(R); try { XmlSchemaCollection xsc = new XmlSchemaCollection(); xsc.Add("", SchemaFile); V.Schemas.Add(xsc);
0
10305
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7598
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.