Practical
Learning: Introducing XML
|
|
- Start Microsoft Visual C# and create a Console
Application named CollegeParkAutoParts1
- To save the application, on the Standard toolbar, click the Save All
button
- Accept all defaults and click Save
Writing XML Code Using XmlDocument |
|
To create XML code using XmlDocument, this
class has a method called LoadXml(). Its syntax is:
public virtual void LoadXml(string xml);
This method takes a string as argument.
The XmlDocument.LoadXml() method doesn't create an XML file, it
only allows you to provide or create XML code. The code can be created as
argument. You can also first declare and initialize a string
variable with the XML code, then pass
it as argument to the XmlDocument.LoadXml()
method.
Practical
Learning: Creating an XML Document
|
|
- To start with XML, change the Program.cs file as
follows:
using System;
using System.Xml;
namespace CollegeParkAutoParts1
{
class Program
{
static int Main(string[] args)
{
XmlDocument docXML = new XmlDocument();
docXML.LoadXml("");
return 0;
}
}
}
|
- Save the Program.cs file
Writing XML Code Using the Code Editor |
|
In the next sections, we will see how to create an XML file
with the Add New Item dialog box. After creating the file and displaying it in the
Code Editor, you can start editing it. The
Code Editor is equipped to assist you with various options. Whenever you start
typing, the editor would display one or more options to you. Here is an example:
When different options are presented to you, you can press
the arrow keys to select an option and press Enter. You can also use the mouse
to click an option. When typing other XML items as we will learn, the Code
Editor is equipped to work in concert with you.
|