Home » Microsoft Technologies

XmlWrite using full namespace

How using XmlWriter to write xml using full namespace and its schema definition ?

like this :

<customer xmlns="xxxx"
     xsi:schemaLocation ="xxxx xxx.xsd">


4 Answers Found


Answer 1

conststring NS = "xxxx";
conststring XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";

xw.WriteStartElement("customer", NS);
xw.WriteAttributeString("xmlns", NS);
xw.WriteAttributeString("xmlns", "xsi", null, XSI_NS);
xw.WriteAttributeString("schemaLocation", XSI_NS, NS + " xxx.xsd");
// Write content here.

Please direct further xml  questions to the XML forum: http://social.msdn.microsoft.com/Forums/en-US/xmlandnetfx/threads



Answer 2

I using XmlSerializer and this is the code :

XmlSerializerNamespaces xmlnsEmpty = new XmlSerializerNamespaces();
            xmlnsEmpty.Add("", "");

            XmlWriterSettings xmlwtSettings = new XmlWriterSettings();
            xmlwtSettings.OmitXmlDeclaration = true;
            //xmlwtSettings.Indent = true;

            StringBuilder stringBuilder = new StringBuilder();
            XmlWriter xmlWriter = XmlWriter.Create(stringBuilder, xmlwtSettings);

            if (xmlWriter != null)
                serializer.Serialize(xmlWriter, this, xmlnsEmpty);

where and how to put this attributes

     xsi:schemaLocation ="xxxx xxx.xsd"


Answer 3

If you want your .NET objects to be serialized in an XML namespace  then use the Namespace property of the XmlRootAttribute attribute when you add the serialization attributes to your code e.g.


public class Foo { ... }


Answer 4

ok tats for the namespace... what about other attribute xsi:schemaLocation ="xxxx xxx.xsd"


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure