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.