FabrizioSW@gmail.com wrote:
[color=blue]
> i'm writting an application reading from db and creating
> xml document, i think i can use textwrite as well, however also i'd
> like to know how to use XmlDocument to achieve this goal...[/color]
Ok, first a corrected version of the XmlTextWriter example (as I think
in the first answer I messed up local names and prefixes and the result
was not as in your original request)
XmlTextWriter xmlWriter = new XmlTextWriter("file.xml", Encoding.UTF8);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("Main");
xmlWriter.WriteAttributeString("xmlns", "x",
"http://www.w3.org/2000/xmlns/", "http://www.w3.org/1999/XML/xinclude");
xmlWriter.WriteStartElement("include",
"http://www.w3.org/1999/XML/xinclude");
xmlWriter.WriteAttributeString("href", "one.xml");
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("include",
"http://www.w3.org/1999/XML/xinclude");
xmlWriter.WriteAttributeString("href", "two.xml");
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("include",
"http://www.w3.org/1999/XML/xinclude");
xmlWriter.WriteAttributeString("href", "more.xml");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
As for doing it with XmlDocument, here is an example
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.AppendChild(xmlDocument.CreateElement( "Main"));
XmlAttribute attribute = xmlDocument.CreateAttribute("xmlns", "x",
"http://www.w3.org/2000/xmlns/");
attribute.Value = "http://www.w3.org/1999/XML/xinclude";
xmlDocument.DocumentElement.SetAttributeNode(attri bute);
XmlElement element = xmlDocument.CreateElement("x:include",
"http://www.w3.org/1999/XML/xinclude");
element.SetAttribute("href", "one.xml");
xmlDocument.DocumentElement.AppendChild(element);
element = xmlDocument.CreateElement("x:include",
"http://www.w3.org/1999/XML/xinclude");
element.SetAttribute("href", "two.xml");
xmlDocument.DocumentElement.AppendChild(element);
element = xmlDocument.CreateElement("x:include",
"http://www.w3.org/1999/XML/xinclude");
element.SetAttribute("href", "two.xml");
xmlDocument.DocumentElement.AppendChild(element);
// now save somewhere e.g.
xmlDocument.Save(Console.Out);
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/