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>”
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)));
System.Xml
XElement/XDocument