There is also LINQtoXSD (not XmlSerializer, sure :-)
pst
2010-07-21 17:04:01
Ok guys i just found the answer here to my questions and im writing here to help people with this problem:
public static string SerializeToXMLString(object ObjectToSerialize)
{
//
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("ns", "http://example.uri.here");
//
//
XmlSerializer serializer = new XmlSerializer(ObjectToSerialize.GetType());
XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.OmitXmlDeclaration = true;
StringWriter stringWriter = new StringWriter();
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, writerSettings))
{
serializer.Serialize(xmlWriter, ObjectToSerialize,ns);
}
return stringWriter.ToString();
}
To solve the prefix : I created a XmlSerializerNamespaces object and added the prefix that I wanted and the namespace.
To solve the ns:pay ns:payment I created two classes: Payment and Pay.
In the pay class i added this: [XmlRoot("pay", Namespace = "http://example.uri.here")]
In the Payment Class i added this: [XmlRoot("pay")]
Pay Class has a property of type payment. That create the xml in this style:
<ns:pay>
<ns:payment
element here
</ns:payemnt>
</ns:pay>
Thank you guys. Sorry that I ask and found the question almost 30 minutes after asking.