using System.Xml;
XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("books");
doc.AppendChild(root);
XmlElement eltBook = doc.CreateElement("book");
root.AppendChild(eltBook);
XmlElement eltTitle = doc.CreateElement("title");
eltTitle.AppendChild(doc.CreateTextNode("myTitle"));
eltBook.AppendChild(eltTitle);
XmlElement eltAuthor = doc.CreateElement("author");
eltAuthor.AppendChild(doc.CreateTextNode("myAuthor"));
eltBook.AppendChild(eltAuthor);
XmlElement eltPrice = doc.CreateElement("price");
eltPrice.AppendChild(doc.CreateTextNode("10.0"));
eltBook.AppendChild(eltPrice);
doc.Save("a.xml");
<books>
<book>
<title>myTitle</title>
<author>myAuthor</author>
<price>10.0</price>
</book>
</books>
using System.Xml;
XmlDocument doc = new XmlDocument();
XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(docNode);
XmlNode productsNode = doc.CreateElement("products");
doc.AppendChild(productsNode);
XmlNode productNode = doc.CreateElement("product");
XmlAttribute productAttribute = doc.CreateAttribute("id");
productAttribute.Value = "1001";
productNode.Attributes.Append(productAttribute);
productsNode.AppendChild(productNode);
XmlNode nameNode = doc.CreateElement("productName");
nameNode.AppendChild(doc.CreateTextNode("Gourmet Coffee"));
productNode.AppendChild(nameNode);
XmlNode priceNode = doc.CreateElement("productPrice");
priceNode.AppendChild(doc.CreateTextNode("0.99"));
productNode.AppendChild(priceNode);
doc.Save("a.xml");
<?xml version="1.0" encoding="UTF-8"?>
<products>
<product id="1001">
<productName>Gourmet Coffee</productName>
<productPrice>0.99</productPrice>
</product>
</products>
XmlTextReader reader = new XmlTextReader("test.xml");
// Read the File
while (reader.Read())
{
}
if (reader != null)
reader.Close();
string localURL = "http:.............Test.xml";
XmlTextReader myXmlURLreader = null;
myXmlURLreader = new XmlTextReader(localURL);
while (myXmlURLreader.Read())
{
//TODO -
}
if (myXmlURLreader != null)
myXmlURLreader.Close();
string localURL = "http:.............Test.xml";
XmlTextReader myXmlURLreader = null;
myXmlURLreader = new XmlTextReader(localURL);
while (myXmlURLreader.Read())
{
//TODO -
}
if (myXmlURLreader != null)
myXmlURLreader.Close();