الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

how write xml log file

مغلق
بدأه mufic_semsem في 30 يونيو 2007 · 3 رد · 713 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

how to wite and read in xml file

i need to make a log file to my program in an XML form

لا اله الا الله .......................................... محمد رسول الله

#2

من فضلك يا أخي استخدم اللغة العربية في المنتدى هنا حتى يفهمك الجميع خصوصا أن لغتك الإنجليزية واضح أنها ضعيفة.

قواعد طرح الأسئلة والمشاركات :

/index.php?showtopic=29343

#Read

http://MoutazShams.blogspot.com

projects003.gif

أعتذر عن التغيب هذه الأيام نظرا للانشغال المريب

#3

السلام عليكم

ازاى اكتب و اقرا من file مكتوب بالــ XML

:)

لا اله الا الله .......................................... محمد رسول الله

#4

write in xml file

using System;
using System.IO;
using System.Xml;

public class Sample
{
  private const string filename = "sampledata.xml";

  public static void Main()
  {
	 XmlTextWriter writer = null;

	 writer = new XmlTextWriter (filename, null);
	 //Use indenting for readability.
	 writer.Formatting = Formatting.Indented;

	 //Write the XML delcaration. 
	 writer.WriteStartDocument();

	 //Write the ProcessingInstruction node.
	 String PItext="type='text/xsl' href='book.xsl'";
	 writer.WriteProcessingInstruction("xml-stylesheet", PItext);

	 //Write the DocumentType node.
	 writer.WriteDocType("book", null , null, "<!ENTITY h 'hardcover'>");

	 //Write a Comment node.
	 writer.WriteComment("sample XML");

	 //Write a root element.
	 writer.WriteStartElement("book");

	 //Write the genre attribute.
	 writer.WriteAttributeString("genre", "novel");

	 //Write the ISBN attribute.
	 writer.WriteAttributeString("ISBN", "1-8630-014");

	 //Write the title.
	 writer.WriteElementString("title", "The Handmaid's Tale");

	 //Write the style element.
	 writer.WriteStartElement("style");
	 writer.WriteEntityRef("h");
	 writer.WriteEndElement(); 

	 //Write the price.
	 writer.WriteElementString("price", "19.95");

	 //Write CDATA.
	 writer.WriteCData("Prices 15% off!!");

	 //Write the close tag for the root element.
	 writer.WriteEndElement();

	 writer.WriteEndDocument();

	 //Write the XML to file and close the writer.
	 writer.Flush();
	 writer.Close();  

	 //Load the file into an XmlDocument to ensure well formed XML.
	 XmlDocument doc = new XmlDocument();
	 //Preserve white space for readability.
	 doc.PreserveWhitespace = true;
	 //Load the file.
	 doc.Load(filename);  

	 //Display the XML content to the console.
	 Console.Write(doc.InnerXml);  

  }

}

read xml

using System;
using System.IO;
using System.Xml;

public class Sample {

  private const String filename = "items.xml";

  public static void Main() {

	 XmlTextReader reader = null;

	 try {

		// Load the reader with the data file and ignore all white space nodes.		 
		reader = new XmlTextReader(filename);
		reader.WhitespaceHandling = WhitespaceHandling.None;

		// Parse the file and display each of the nodes.
		while (reader.Read()) {
		   switch (reader.NodeType) {
			 case XmlNodeType.Element:
			   Console.Write("<{0}>", reader.Name);
			   break;
			 case XmlNodeType.Text:
			   Console.Write(reader.Value);
			   break;
			 case XmlNodeType.CDATA:
			   Console.Write("<![CDATA[{0}]]>", reader.Value);
			   break;
			 case XmlNodeType.ProcessingInstruction:
			   Console.Write("<?{0} {1}?>", reader.Name, reader.Value);
			   break;
			 case XmlNodeType.Comment:
			   Console.Write("<!--{0}-->", reader.Value);
			   break;
			 case XmlNodeType.XmlDeclaration:
			   Console.Write("<?xml version='1.0'?>");
			   break;
			 case XmlNodeType.Document:
			   break;
			 case XmlNodeType.DocumentType:
			   Console.Write("<!DOCTYPE {0} [{1}]", reader.Name, reader.Value);
			   break;
			 case XmlNodeType.EntityReference:
			   Console.Write(reader.Name);
			   break;
			 case XmlNodeType.EndElement:
			   Console.Write("</{0}>", reader.Name);
			   break;
		   }	   
		}		   
	 }

	 finally {
		if (reader!=null)
		  reader.Close();
	 }
  }
} // End class

و شكرااااااااااااااااااااا

لا اله الا الله .......................................... محمد رسول الله

هذا الموضوع مغلق.

مواضيع مشابهة