c# - Using a XML DataReader -
i using sqldatareader
read data scenarios
table such:
string data = reader["scenariodata"].tostring();
however, scenariodata
field xml ntext
. how can read xml data datareader
? example, lets wanted read url "http://google.com".
scenario data field:
<scenario name="scenario1" feature="feature1"> <steps> <step url="http://google.com"></step> </steps> </scenario>
given fact have xml in variable of type string, suggest following :
sqldatareader reader= cmd.executereader(); while (reader.read()) { ..... // have xml string stocked in data string data = (string)reader["scenariodata"]; // parse var doc = xdocument.parse(data); var step = doc.descendants("step").attributes().firstordefault(); var url = step != null ? step.value : string.empty; ...... }
there way read xml using sqlxml, can find more information here
Comments
Post a Comment