Get XML data and xml

Source: Internet
Author: User

Get XML data and xml

Http://www.w3school.com.cn/xml/xml_elements.asp

 

<? Xml version = "1.0" encoding = "gb2312"?>
<String xmlns = "http://tempuri.org/"> 5/6/0:06:05 </string>

Obtain 5/6, 0:06:05 in the preceding XML

<?xml version="1.0" encoding="gb2312"?><string xmlns="http://tempuri.org/">200,2014/5/6 0:06:05</string>

 

Using System; using System. collections. generic; using System. linq; using System. text; using System. data. entity. validation; using System. data. entity; using System. data. objects; using System. web; using System. xml; namespace Test {class Program {static void Main (string [] args) {XmlDocument xml = new XmlDocument (); xml. load (".. /.. /1.xml"); // The XML file is loaded in, and the path is viewed. The relative path is used here. The XmlNode node = xml, which is definitely better than the path. lastChild; foreach (XmlNode item in node. childNodes) {Console. writeLine (item. innerXml); Console. writeLine (item. innerText); // string v = item. value; // node Value // string v1 = item. attributes ["xmlns"]. value; // node attribute Value. An error is returned when this parameter is obtained. The node data is incorrect and other XML data is required. // string v2 = item ["string"]. value; // element Value // string v3 = item ["string"]. attributes ["xmlns"]. value; // element property Value // Console. writeLine (v); // Console. writeLine (v1); // Console. writeLine (v2); // Console. writeLine (v3);} Console. readKey ();}}Get XML content XmlDocument xml = new XmlDocument () {InnerXml = @ "<? Xml version = '1. 0' encoding = 'gb2312 '?> <String xmlns = 'HTTP: // tempuri.org/'> 5/6/0:06:05 </string> "};Initialize XMLXmlDocument xml = new XmlDocument (); xml. LoadXml (@ "<? Xml version = '1. 0' encoding = 'gb2312 '?> <String xmlns = 'HTTP: // tempuri.org/'> 5/6/0:06:05 </string> "); Console. WriteLine (xml. InnerXml. ToString ());Initialize XML

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.