Re: Elimnating namespace in XML
- From: Daniel Strigl <daniel.strigl@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 07 Aug 2007 11:09:00 +0200
Hi Barry!
I need generate an XML message without the namespace using XmlSerializer, have tried XmlRootAttribute without much help
I need to elimate xmlns:xsd=......
- <OrderStatus xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
The following sample shows how it works:
public class Student
{
public string Name;
public int ID;
}
public class Program
{
static void Main(string[] args)
{
// Create an instance of the object to serialize
Student student = new Student();
student.Name = "John Doe";
student.ID = 1234;
// Create our own namespaces for the output
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
// Add an empty namespace and empty value
ns.Add("", "");
// Create the serializer
XmlSerializer serializer =
new XmlSerializer(typeof(Student));
// Serialize the object with our own namespaces
TextWriter writer = new StreamWriter("student.xml");
serializer.Serialize(writer, student, ns);
writer.Close();
}
}
More info can be found at:
http://www.csharper.net/blog/serializing_without_the_namespace__xmlns__xmlns_xsd__xmlns_xsi_.aspx.
Regards,
Daniel.
--
Daniel Strigl [daniel.strigl@xxxxxxxxxxxxxxxxxx, remove 'takethisout.']
Web: http://www.hh-system.com/danielstrigl
Blog: http://geekswithblogs.net/dastblog
.
- References:
- Elimnating namespace in XML
- From: Barry
- Elimnating namespace in XML
- Prev by Date: Elimnating namespace in XML
- Next by Date: Directory Based Authorization
- Previous by thread: Elimnating namespace in XML
- Next by thread: Directory Based Authorization
- Index(es):
Relevant Pages
|