Xmldocument, xmlnode, and xmlelement to create complex XML documents

Source: Internet
Author: User
# Region Generate XML Message
Xmldocument xmldoc =   New Xmldocument ();


// Generate description version
Xmldeclaration xmldec;
Xmldec = Xmldoc. createxmldeclaration ( " 1.0 " , " Gb2312 " , " Yes " );
Xmldoc. insertbefore (xmldec, xmldoc. documentelement );

// Define the root node
Xmlelement element;
Xmlnode rootnode;
Xmlnode subnode;
Element = Xmldoc. createelement ( " Message " );
Element. setattribute ( " System " , " ATMs " );
Element. setattribute ( " Ver " , " 1.0 " );
Rootnode = Xmldoc. appendchild (element );

// Define Subsystem
Element = Xmldoc. createelement ( " Systemtype " );
Element. innertext = Subtype;
Rootnode. appendchild (element );

// Define Message Types
Element = Xmldoc. createelement ( " Messagetype " );
Element. innertext =   " Alarm " ;
Rootnode. appendchild (element );

// Define Subsystem
Element = Xmldoc. createelement ( " Systemtype " );
Element. innertext = Subtype;
Rootnode. appendchild (element );

// Source IP address of the sent message
Element = Xmldoc. createelement ( " Sourceip " );
Element. innertext =   "" ;
Rootnode. appendchild (element );

// Destination IP address for receiving messages
Element = Xmldoc. createelement ( " Sourceip " );
Element. innertext =   "" ;
Rootnode. appendchild (element );

// User Name
Element = Xmldoc. createelement ( " User " );
Element. innertext =   "" ;
Rootnode. appendchild (element );

// Password
Element = Xmldoc. createelement ( " Password " );
Element. innertext =   "" ;
Rootnode. appendchild (element );

Element = Xmldoc. createelement ( " Alarm " );
Element. innertext =   "" ;
Rootnode. appendchild (element );

Element = Xmldoc. createelement ( " Type " );
Element. innertext =   "" ;
Rootnode. lastchild. appendchild (element );

Element = Xmldoc. createelement ( " Device " );
Element. innertext =   "" ;
Subnode = Rootnode. lastchild. appendchild (element );

Element = Xmldoc. createelement ( " ID " );
Element. innertext =   "" ;
Subnode. appendchild (element );

Element = Xmldoc. createelement ( " Name " );
Element. innertext =   "" ;
Subnode. appendchild (element );

Element = Xmldoc. createelement ( " Location " );
Element. innertext =   "" ;
Subnode. appendchild (element );

Element = Xmldoc. createelement ( " Errortype " );
Element. innertext =   "" ;
Subnode. appendchild (element );

Element = Xmldoc. createelement ( " Occurtime " );
Element. innertext =   "" ;
Subnode. appendchild (element );

Element = Xmldoc. createelement ( " Releasetime " );
Element. innertext =   "" ;
Subnode. appendchild (element );

Element = Xmldoc. createelement ( " Desc " );
Element. innertext =   "" ;
Subnode. appendchild (element );

String X = Xmldoc. outerxml;
# Endregion

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.