开发者

How do you read xml data from a project resource into a dataset?

I have an xml file that is a project resource. I can access it via Properties.Resources.DrivereSettings. The xml file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<FilterOffsets>
  <FocusOffset>
    <SerialNumber>12543</SerialNumber>
    <Filter>4</Filter>
    <Wheel>A</Wheel>
    <Offset>7</Offset>
  </FocusOffset>
</FilterOffsets>

I want to load this data into the dataset of an xmlDataDocument. If I use this code, xmlDataDoc.LoadXml(Properties.Resources.DriverSettings); The data does not get loa开发者_运维问答ded into the dataset. There are 0 tables. Is that because my xml is formatted incorrectly? How can I get the data into the dataset and then make changes to the dataset and write them back to the xml?


What you need to do is to first read the resource into a String, and then use loadXml from that String.


put your xml text in StringReader like below

System.IO.StringReader sr = new System.IO.StringReader(xmltext);

ds.ReadXml(sr);

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜