0

I want to retrieve the XML data from db and bound it to the DropDownList.

XML data in the db field is follows:

<Root>
    <ClientName>Jim</ClientName>
    <ClientName>John</ClientName>
    <ClientName>Andrew</ClientName>
</Root>

i retrieved the xml data from db field. but, i got next error:

Data at the root level is invalid. Line 1, position 1

The following code used to retrieve the xml data from db field. do you have any idea about this problem?

var list = from drp in zephyrEntities.UserDefinedFields
           where drp.UDF_ID == udfid
           select drp.LIST_VALUES; // xml field in the db

XmlDocument doc = new XmlDocument();
XElement xelement = new XElement("UserDefinedList", list);
string str = String.Concat(xelement.Nodes());
doc.LoadXML(str);
XmlNodeList childNodes = doc.GetElementsByTagName("ClientName");
if (childNodes != null)
{
    for (int i = 0; i < childNodes.Count; i++)
    {
        XmlNode valueNode = childNodes[i].SelectSingleNode("text()");
    }
}
3
  • 1
    It would help if you'd say where the error occurred. Also, when you've already got the XML in an XElement, why are you then building an XmlDocument from it, and in a strange way? Commented Nov 24, 2010 at 9:51
  • 3
    You should use either System.Xml.XmlDocument or System.Xml.Linq.XElement. Not both! Commented Nov 24, 2010 at 10:12
  • hi jon, i want to read the data from xelement.so, i load the xelement in the xml document. the error occured at doc.LoadXML(str) line. Commented Nov 25, 2010 at 10:59

1 Answer 1

1

It is not clear why you store list of entities as one value. Try to normalize your DB model.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.