Untitled


SUBMITTED BY: Guest

DATE: Nov. 23, 2013, 6:10 p.m.

FORMAT: Text only

SIZE: 1.5 kB

HITS: 6479

  1. string Data = reader["ScenarioData"].ToString();
  2. <Scenario Name="Scenario1" Feature="Feature1">
  3. <Steps>
  4. <Step Url="http://google.com"></Step>
  5. </Steps>
  6. </Scenario>
  7. SqlXml sqlXml = reader["ScenarioData"].GetSqlXml();
  8. using (var reader = sqlXml.CreateReader())
  9. {
  10. // Do something with the XML, like maybe
  11. var doc = XDocument.Load(reader);
  12. var url = doc.Element("Scenario")
  13. .Element("Steps")
  14. .Element("Step")
  15. .Attribute("Url")
  16. .Value;
  17. // etc.
  18. }
  19. SqlDataReader reader= cmd.ExecuteReader();
  20. while (reader.Read())
  21. {
  22. .....
  23. // you have already an xml string stocked in data
  24. string data = (string)reader["ScenarioData"];
  25. // parse it
  26. var doc = XDocument.Parse(data);
  27. var step = doc.Descendants("Step").Attributes().FirstOrDefault();
  28. var url = step != null ? step.Value : String.Empty;
  29. ......
  30. }
  31. using System.Xml.Linq;
  32. var xml = XElement.Parse(reader["ScenarioData"].ToString());
  33. //assuming there can be multiple <step> elements
  34. var steps = xml.Element("Scenario").Element("Steps").Elements("Step");
  35. var url = steps.First().Attribute("Url").Value;

comments powered by Disqus