XML read and write .....

xiaoxiao2021-03-06  101

=================== Using system; use system.drawing; use system.collections; use system.componentmodel; using system.windows.form; using system.data; using Summary for system.xml; using system.x; using system.xml.xpath; namespace xmlcreation {///

/// form1 summary description. /// public class Form1: System.Windows.Forms.Form {private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.treeView TreeView1; /// // / / The designer variable is required. /// private system.componentmodel.container components = null;

Public Form1 () {// // Windows Form Designer Support for // InitializeComponent ();

// // Todo: Add any constructor code after INITIALIZEComponent call //}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();}} Base.Dispose

#REGION Windows Form Designer The code ///

/// designer supports the required method - do not use the code editor to modify the // / this method.

/// private void InitializeComponent () {this.textBox1 = new System.Windows.Forms.TextBox (); this.button1 = new System.Windows.Forms.Button (); this.button2 = new System. Windows.Forms.Button (); this.treeview1 = new system.windows.forms.treeview (); this.suspendlayout (); ////////////////////////////////////////////////////////////////////////////////////////////////////////> AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right))); this.textBox1.Location = new System.Drawing. Point (128, 8); this.textBox1.Multiline = true; this.textBox1.Name = "textBox1"; this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.textBox1.Size = new System. Drawing.size (304, 312); this.textBox1.tabindex = 0; this.textBox1.text = ""; /// Button1 // this.button1.anchor = ((System.Windows.Forms.Anchorstyles) (System.Windows.Forms.Anchorstyles.bottom | System.windows.Forms.Anchorstyles.left)); This.Button1.Location = new system.drawing.point (48, 328); this.button1.name = "button1"; this.button1.tabindex = 1; this.button1.text = "create"; this.button1. Click = New System.EventHandler (this.button1_click); // // Button2 // this.button2.ancy = ((System.Windows.Forms.Anchorstyles ") ((System.Windows.Forms.Anchorstyles.Bottom | System. Windows.Forms.Anchorstyles.right))); this.Button2.Location = new system.drawing.point (320, 328); this.button2.name = "button2"; this.button2.tabindex = 2; this.button2 .Text = "path"; this.button2.click =

new System.EventHandler (this.button2_Click); // // treeView1 // this.treeView1.Anchor = ((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows .Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.treeView1.ImageIndex = -1; this.treeView1.Location = new System. Drawing.point (8, 8); this.treeview1.name = "treec"; this.treeView1.selectedImageIndex = -1; this.treeView1.size = new system.drawing.size (120, 312); this.treeView1. TabINDEX = 3; // // Form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (440, 357); this.controls.add (this .treeView1); this.controls.add (this.button2); this.controls.add (this.button1); this.controls.add (this.TextBox1); this.name = "form1"; this.text = " Form1 "; this.load = new system.eventhandler (this.form1_load); this.ResumeLayout (false);} #ENDREGI on

///

/// The primary entry point of the application. /// [stathread] static void main () {Application.Run (new form1 ());} private void loadingtree () {xpathDocument doc = new xpathdocument (@ "../../ CustardOrDers.xml "); Xpathnavigator nav = doc.createnavigator (); xpathnodeiterator itrator = nav.select (" // Customers ");

while (iterator.MoveNext ()) {XmlTreeNode node = new XmlTreeNode (iterator.Current); node.FillTreeView (); XPathNodeIterator custIter = iterator.Current.SelectChildren ( "CustomerID", ""); while (custIter.MoveNext () ) Node.Text = Custiter.current.Value; TreeView1.nodes.Add (Node);}}

Private void form1_load (Object sender, system.eventargs e) {// this.loadXML (@ ".. /.); // this.loaddocxml2 (@" ../../ ORDERS.XML "); This.EDITXMLDOC_DEL (@" ../../ Books.xml "); this.loadTree ();} private void editXmldoc_del (string path) {xmldocument DC = new xmldocument (); dc.load (PATH) XMLNodeList ID = dc.getlementsBytagname ("book"); XMLNode Delnd = Null; Foreach (XMLNode ND Id) {IF (Nd.attributes ["ISBN"]. Value == "3-123904-23-4") {This.TextBox1.AppendText (nd.name ":" nd.innerxml); Delnd = nd;}} f (Delnd! = Null) {Delnd.ParentNode.RemoveChild (Delnd); Dc.Save (PATH); }} private void EditXmlDoc_Add (string path) {XmlDocument doc = new XmlDocument (); doc.Load (path); XmlElement newBook ​​= doc.CreateElement ( "book"); newBook.SetAttribute ( "gener", "network"); Newbook.setttribute ("publicationDate", "2002"); newbook.setttribute ("ISBN", "3-123904-23-4"); xmlelement newTITE = Doc.createElement ("Title"); Newti tle.InnerText = "C # Network Programming"; newBook.AppendChild (newTitle); XmlElement newAuthor = doc.CreateElement ( "author"); XmlElement newAuthorFirstName = doc.CreateElement ( "first-name"); newAuthorFirstName.InnerText = "Bill "; XmlElement newAuthorLastName = doc.CreateElement (" last-name "); newAuthorLastName.InnerText =" Gate "; newAuthor.AppendChild (newAuthorFirstName); newAuthor.AppendChild (newAuthorLastName); newBook.AppendChild (newAuthor); XmlElement newPrice = doc. CreateElement ("

"); newprice.innertext =" 100.00 "; newbook.appendchild (newPrice); doc.documentelement .appendchild (newbook); doc.save (pat);

} Private void LoadDocXml2 (string path) {System.Xml.XmlDocument xmldoc = new XmlDocument (); xmldoc.Load (path); XmlNodeList nodes = xmldoc.SelectNodes ( "/ Entity / Sqls / Sql"); foreach (XmlNode nd in Nodes) {THIS.TEXTBOX1.APpendText ("/ R / NSQL statement: / r / n"); xmlattributeCollection atrs = nd.attributes; if (atrs! = null) {Foreach (XMLNode Attrs) {this.TextBox1. AppendText (attr.name ":" attr.innerText "");}} this.textBox1.AppendText ("/ R / n parameter list / r / n"); XMLNodelist Sons = nd.childNodes; Foreach (XMLNode SN In Sons) {Foreach (XMLNode AC in sn.attributes) {this.textBox1.AppendText (ac .Name ":" ac .innertext ");} this.textBox1.appendtext (" / r / n "); }}} private void LoadDocXml (string path) {System.Xml.XmlDocument xmldoc = new XmlDocument (); xmldoc.Load (path); XmlNodeList nodes = xmldoc.SelectNodes ( "/ Entity / Columns / Column"); foreach (XmlNode Node in nodes) {this.textBox1.AppendText (node.name "=== / r / n"); system.xml.xmlattributeCollection IE = node.attributes; if (ie == null) Continue; Foreach (XMLNode Attr in IE) {this.textBox1.AppendText (attr.name ": attr.innerText " ");} this.textbox1.appendtext (" / r / n ");}} private void loading {system.xml.xmlTextReader xr = new xmlTextReader (PATH); while (Xr.Read ()) {if (xr.nodetype == xmlnodetype.element) {textbox1.appendtext ("/ r / way ====" xr.name ":");

IF (Xr.haSattributes) {for (int i = 0; i

private void button2_Click (object sender, System.EventArgs e) {XPathDocument doc = new XPathDocument (@ "../../ books.xml"); System.Xml.XPath.XPathNavigator nav = doc.CreateNavigator (); System. Xml.XPath.XPathNodeIterator itor = nav.SelectDescendants (XPathNodeType.Element, true); while (itor.MoveNext ()) {this.textBox1.AppendText (itor.Current.Name ":"); System.Xml.XPath. XPathNodeIterator chd = itor.Current.SelectChildren (XPathNodeType.Text); while (chd.MoveNext ()) {this.textBox1.AppendText ( ":" chd.Current.Value);} this.textBox1.AppendText ( "/ r / N ");}}}} / orders}}} / orders}}} / orders}}} / ots.xml < / Column>

Employeeid "Direction =" INPUT "> <

Param name = "@ Empid" type = "system.int32" size = "4" SourceColoum = "EMPLOYEEID" Direction = "Input">

sourceColoum = "ShipRegion" Direction = "Input"> books.xml C program design </ title> <author> <first-name> ROLY </ FIRST-NAME> <last-name> nacy </ last-name> </ author> <price> 80.00 </ price> </ book> <book genre = "Database" publicationDate = "2000" ISBN = "1-134559-34-4"> <title> SQL database management </ title> <price> 90.00 </ price> <model> <first-name> Elmer </ First-Name> <last-name> fuld </ last-name> </ author> </ book> <book gener = "network" publicationdate = "2002" ISBN = "3-123904-23-4"> <title > C # Network Program Design </ Title> <author> <first-name> Bill </ first-name> <last-name> Gate </ last-name> </ author> <Price> 100.00 </ price> </ book> </ bookstore></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-101302.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="101302" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.046</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'kEZsh_2FCDXlttk3rsWH2Xir9266HZFM25WbsfcSR4BlROSsO7MUTxL7EzskuwUEDXkVaBhxbutzGE6fVD'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>