Xmldocument, xmlnode, and xmlelement to create complex XML documents
Last Update:2018-12-07
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