C # Reading string-type XML

Source: Internet
Author: User
Today I met XML Attribute Value reading problem, first fromCodeNo errors are found in the train of thought and syntax query problems, Then I found the problem from the client and the server's response information. XML The property value does not appear in this XML String ( XML The string is determined based on the client commands that contain those attributes, that is, different client action commands will send different XML String), so an error occurs.

 

String clientcommand =   " <Move user = \ " ZSP \ " Target = \ " Target_cell \ " Map = \ " Mapid \ " /> " ;
Xmldocument xmldoc =   New Xmldocument (); // Instantiate an xmldocument object
Xmldoc. loadxml (clientcommand ); // Load as XML document
Xmlnode Node = Xmldoc. firstchild; // Extracting the first node of the XML document is actually a node here.
Xmlattribute user = Node. attributes [ " User " ];
String name = User. value. tostring (); // Assign the user attribute value to a string
Xmlattribute Map = Node. attributes [ " Map " ];
String clientmap = Map. value. tostring (); // Assign the value of the map attribute to a string
Console. writeline ( " Name: {0}, MAP: {1} " , Name, clientmap );

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.