ITsolutionWizard
asked on
XML & .net
I have super simple xml and below .net c# codes and just try to read
stepID=1 and controlID=state and it should return two states under <Data></Data> but it does not happen. not sure why and need experts helping.
Thanks
public string GetOptionList(string stepID, string controlID)
{
string tmpStr = string.Empty;
XmlDocument myXml = new XmlDocument();
myXml.Load(Server.MapPath( "~") + "\\testStructure.xml");
XmlNodeList oXmlNodeList = myXml.SelectNodes("Structu re/Step[@I D=" + stepID + "]/Section/Control[ID=" + controlID + "]/Data");
foreach (XmlNode x in oXmlNodeList)
{
string option = x.SelectSingleNode("Option ").InnerTe xt;
tmpStr = tmpStr + "<option>" + option + "</option>";
}
return tmpStr;
}
stepID=1 and controlID=state and it should return two states under <Data></Data> but it does not happen. not sure why and need experts helping.
Thanks
public string GetOptionList(string stepID, string controlID)
{
string tmpStr = string.Empty;
XmlDocument myXml = new XmlDocument();
myXml.Load(Server.MapPath(
XmlNodeList oXmlNodeList = myXml.SelectNodes("Structu
foreach (XmlNode x in oXmlNodeList)
{
string option = x.SelectSingleNode("Option
tmpStr = tmpStr + "<option>" + option + "</option>";
}
return tmpStr;
}
<?xml version="1.0" encoding="utf-8" ?>
<Structure>
<Step ID="1">
<Section>
<Control>
<Label>First Name</Label>
<ID>firstName</ID>
<Type>Text</Type>
<Cols>4</Cols>
<Data>
<Option>None</Option>
</Data>
<Required>No</Required>
</Control>
<Control>
<Label>Last Name</Label>
<ID>lastName</ID>
<Type>Text</Type>
<Cols>4</Cols>
<Data>
<Option>None</Option>
</Data><Required>No</Required>
</Control>
<Control>
<Label>State</Label>
<ID>state</ID>
<Type>Select</Type>
<Cols>4</Cols>
<Data>
<Option>CA</Option>
<Option>TX</Option>
</Data><Required>No</Required>
</Control>
<Control>
<Label>Do You Like Me?</Label>
<ID>LikeIt</ID>
<Type>Select</Type>
<Cols>4</Cols>
<Data>
<Option>Yes</Option>
<Option>No</Option>
</Data>
<Required>No</Required>
</Control>
</Section>
</Step>
<Step ID="2">
<Section>
<Control>
<Label>First Name</Label>
<ID>firstName</ID>
<Type>Text</Type>
<Cols>4</Cols>
<Data>
<Option>None</Option>
</Data><Required>No</Required>
</Control>
</Section>
</Step>
<Step ID="3">
<Section>
<Control>
<Label>First Name</Label>
<ID>firstName</ID>
<Type>Text</Type>
<Cols>4</Cols>
<Data>
<Option>None</Option>
</Data><Required>No</Required>
</Control>
<Control>
<Label>Last Name</Label>
<ID>lastName</ID>
<Type>Text</Type>
<Cols>4</Cols>
<Data>
<Option>None</Option>
</Data><Required>No</Required>
</Control>
<Control>
<Label>State</Label>
<ID>state</ID>
<Type>Select</Type>
<Cols>4</Cols>
<Data>
<Option>CA</Option>
<Option>TX</Option>
</Data><Required>No</Required>
</Control>
</Section>
</Step>
</Structure>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think it's XPATH is incorrect it should be something like this:
/Structure/Step[@ID='1']/S ection/Con trol[ID='f irstName'] /Data/Opti on
Also single quotes for "stepID" are missing I corrected it below.
Change the following line to
/Structure/Step[@ID='1']/S
Also single quotes for "stepID" are missing I corrected it below.
Change the following line to
XmlNodeList oXmlNodeList = myXml.SelectNodes("/Structure/Step[@ID='"+ stepID + "']/Section/Control[ID='" + controlID + "']/Data/Option");
ASKER
Best...
well, same thought posted earlier was not being accepted. well done.
Open in new window