473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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" ?>
<DropDownLists xmlns="http://tempuri.org/DropDown.xsd">
<DropDownList name="DataSource">
<Option name="SqlServer" value="SqlServer" />
<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 LoadDropdownMenu(string DropDownName)
{
DropDownList GenericDropDown =
(DropDownList)FindControl(DropDownName);

XPathDocument xpDoc = new XPathDocument(Server.MapPath(".") +
"\\Dropdown.xml", XmlSpace.Preserve);
XPathNavigator xNav = xpDoc.CreateNavigator();

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

while(xNode.MoveNext())
{
GenericDropDown.Items.Add(new
ListItem(xNode.Current.GetAttribute("name",""),xNo de.Current.GetAttribute("value","http://tempuri.org/DropDown.xsd")));
}
}

I don't get any nodes returned in my XPathNodeIterator 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 3201
* Obe wrote in microsoft.public.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 XmlNamespaceManager, 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
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>...
0
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...
7
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
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?...
3
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...
1
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
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() { ...
0
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 ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.