首页 新闻 会员 周边 捐助

C#读取XML内容是什么类?

0
悬赏园豆:10 [已解决问题] 解决于 2012-12-13 08:49

 XmlDocument xmlDoc = new XmlDocument();
        try
        {
            xmlDoc.Load(xmlFileName); //加载XML文件路径
            XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
            return xmlNode;
        }
        catch (Exception ex)
        {
            return null;
            //throw ex; //这里可以定义你自己的异常处理
        }

上面的方法Load()是加载xmlXML文件路径,我现在有一个字符串是xml内容,该怎么读取

string xml=“<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0">
  <Response>
  <name>�й������差�差�г��籱·8��</name>
  <Status>
    <code>200</code>
    <request>geocode</request>
  </Status>
  <Placemark id="p1">
    <address>�й�����ʡ�差���������籱·38���差�������� ��������: 441057</address>
    <AddressDetails Accuracy="9" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>CN</CountryNameCode><CountryName>�й�</CountryName><AdministrativeArea><AdministrativeAreaName>����ʡ</AdministrativeAreaName><Locality><LocalityName>������</LocalityName><DependentLocality><DependentLocalityName>������</DependentLocalityName><Thoroughfare><ThoroughfareName>���籱·38��</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>441057</PostalCodeNumber></PostalCode><AddressLine>�差��������</AddressLine></DependentLocality></Locality></AdministrativeArea></Country></AddressDetails>
    <ExtendedData>
      <LatLonBox north="32.0817436" south="32.0628335" east="112.1503444" west="112.1183296" />
    </ExtendedData>
    <Point><coordinates>112.1343370,32.0722890,0</coordinates></Point>
  </Placemark>
  <Placemark id="p2">
    <address>�й�����ʡ�差���������籱·5�������������������� ��������: 441057</address>
    <AddressDetails Accuracy="9" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>CN</CountryNameCode><CountryName>�й�</CountryName><AdministrativeArea><AdministrativeAreaName>����ʡ</AdministrativeAreaName><Locality><LocalityName>������</LocalityName><DependentLocality><DependentLocalityName>������</DependentLocalityName><Thoroughfare><ThoroughfareName>���籱·5��</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>441057</PostalCodeNumber></PostalCode><AddressLine>������������������</AddressLine></DependentLocality></Locality></AdministrativeArea></Country></AddressDetails>
    <ExtendedData>
      <LatLonBox north="32.0570296" south="32.0543316" east="112.1362339" west="112.1335359" />
    </ExtendedData>
    <Point><coordinates>112.1348849,32.0556806,0</coordinates></Point>
  </Placemark>
  <Placemark id="p3">
    <address>�й�����ʡ�差���������籱·26����������۾ַ��Ƿ־� ��������: 441057</address>
    <AddressDetails Accuracy="9" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>CN</CountryNameCode><CountryName>�й�</CountryName><AdministrativeArea><AdministrativeAreaName>����ʡ</AdministrativeAreaName><Locality><LocalityName>������</LocalityName><DependentLocality><DependentLocalityName>������</DependentLocalityName><Thoroughfare><ThoroughfareName>���籱·26��</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>441057</PostalCodeNumber></PostalCode><AddressLine>��������۾ַ��Ƿ־�</AddressLine></DependentLocality></Locality></AdministrativeArea></Country></AddressDetails>
    <ExtendedData>
      <LatLonBox north="32.0655651" south="32.0628671" east="112.1357081" west="112.1330101" />
    </ExtendedData>
    <Point><coordinates>112.1343591,32.0642161,0</coordinates></Point>
  </Placemark>
  <Placemark id="p4">
    <address>�й�����ʡ�差���������籱·26����������۾ּ۸�ٱ����� ��������: 441057</address>
    <AddressDetails Accuracy="9" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>CN</CountryNameCode><CountryName>�й�</CountryName><AdministrativeArea><AdministrativeAreaName>����ʡ</AdministrativeAreaName><Locality><LocalityName>������</LocalityName><DependentLocality><DependentLocalityName>������</DependentLocalityName><Thoroughfare><ThoroughfareName>���籱·26��</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>441057</PostalCodeNumber></PostalCode><AddressLine>��������۾ּ۸�ٱ�����</AddressLine></DependentLocality></Locality></AdministrativeArea></Country></AddressDetails>
    <ExtendedData>
      <LatLonBox north="32.0655651" south="32.0628671" east="112.1357081" west="112.1330101" />
    </ExtendedData>
    <Point><coordinates>112.1343591,32.0642161,0</coordinates></Point>
  </Placemark>
  <Placemark id="p5">
    <address>�й�����ʡ�差���������籱·18�������н��蹤����۹���վ ��������: 441003</address>
    <AddressDetails Accuracy="9" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>CN</CountryNameCode><CountryName>�й�</CountryName><AdministrativeArea><AdministrativeAreaName>����ʡ</AdministrativeAreaName><Locality><LocalityName>������</LocalityName><DependentLocality><DependentLocalityName>������</DependentLocalityName><Thoroughfare><ThoroughfareName>���籱·18��</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>441003</PostalCodeNumber></PostalCode><AddressLine>�����н��蹤����۹���վ</AddressLine></DependentLocality></Locality></AdministrativeArea></Country></AddressDetails>
    <ExtendedData>
      <LatLonBox north="32.0622153" south="32.0595173" east="112.1359947" west="112.1332967" />
    </ExtendedData>
    <Point><coordinates>112.1346457,32.0608663,0</coordinates></Point>
  </Placemark>
</Response>
</kml>”

truename的主页 truename | 初学一级 | 园豆:168
提问于:2012-12-12 16:54
< >
分享
最佳答案
0

string xmlStr = "<doc><assembly><name>XMLdoc</name></assembly></doc>";
DataSet dataSet = new DataSet();
dataSet.ReadXml(new System.IO.MemoryStream(System.Text.Encoding.Default.GetBytes(xmlStr)));

收获园豆:5
Rich.T | 老鸟四级 |园豆:3440 | 2012-12-12 16:58
其他回答(3)
0

呵呵 我这里有一个我写的例子你可以参考一下,增加 修改,删除都有

C#操作Xml(增、删、改、查)限制访问IP操作

收获园豆:3
苏飞 | 园豆:2024 (老鸟四级) | 2012-12-12 17:19
0

System.Xml

收获园豆:1
angelshelter | 园豆:9914 (大侠五级) | 2012-12-12 21:00
0

XElement/XDocument

收获园豆:1
中文代码 | 园豆:951 (小虾三级) | 2012-12-13 08:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册