I got a problem and I hope somebody can help me, because I can´t find the solution by myself.
I want to write an XML File with Csharp and the file needs to begin like that:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.link2
http://www.link3"
My code is the following:
using System;
using System.Data;
using System.Text;
using System.Xml;
using System.IO;
using System.Reflection;
using System.Diagnostics;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
// XmlWriter for an UTF-8-Coding with indent
XmlWriter xmlWriter = null;
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = " ";
//Filename of the XML File
string appPath = Path.GetDirectoryName(
Assembly.GetEntryAssembly().Location);
string xmlFileName = Path.Combine(appPath, "test.xml");
xmlWriter = XmlWriter.Create(xmlFileName, settings);
// standalone
xmlWriter.WriteStartDocument(true);
// Startelement with namespace
xmlWriter.WriteStartElement("Comprobant",
"http://link1");
xmlWriter.WriteStartElement("Emiss"); //Element name
xmlWriter.WriteElementString("street", "mystreet");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Close();
// show xml
Process.Start(xmlFileName);
}
}
}
And my XML that is generated is:
I don´t know what to do. Please help me out ..
How can I add these lines: ??????
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.link2
http://www.link3"
Greetings Dom
Roei BarPosted Aug 14, 2009, 7:38 AM
dont forget to mark this as "Accepted Answer" :-)
DominikPosted Aug 14, 2009, 10:19 AM
using System;
using System.Data;
using System.Text;
using System.Xml;
using System.IO;
using System.Reflection;
using System.Diagnostics;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
// XmlWriter for an UTF-8-Coding with indent
XmlWriter xmlWriter = null;
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = " ";
//Filename of the XML File
string appPath = Path.GetDirectoryName(
Assembly.GetEntryAssembly().Location);
string xmlFileName = Path.Combine(appPath, "test.xml");
xmlWriter = XmlWriter.Create(xmlFileName, settings);
const string xmlns1 = "http://link1";
const string ns1 = "http://www.link2 http://www.link3";
const string xsi = "http://www.w3.org/2001/XMLSchema-instance";
// standalone
xmlWriter.WriteStartDocument(true);
// Startelement with namespace
xmlWriter.WriteStartElement("Comprobant",
"http://link1");
//xmlWriter.WriteAttributeString("SchemaVersion", "1.0");
xmlWriter.WriteAttributeString("xmlns", "http://www.w3.org/2000/xmlns/", xmlns1);
xmlWriter.WriteAttributeString("xmlns", "xsi", "http://www.w3.org/2000/xmlns/", xsi);
xmlWriter.WriteAttributeString("xsi", "schemaLocation", xsi, ns1);
xmlWriter.WriteStartElement("Emiss"); //Element name
xmlWriter.WriteElementString("street", "mystreet");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Close();
// show xml
Process.Start(xmlFileName);
}
}
}