开发者

Load XML from DB using C#

开发者 https://www.devze.com 2023-01-26 10:55 出处:网络
I want to retrieve the XML data from db and bound it to the DropDownList. XML data in the db field is follows:

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 childNode开发者_运维问答s = doc.GetElementsByTagName("ClientName");
if (childNodes != null)
{
    for (int i = 0; i < childNodes.Count; i++)
    {
        XmlNode valueNode = childNodes[i].SelectSingleNode("text()");
    }
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号