1
votes

OK so I'm trying to format this XML element so that it looks like this:

<AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

This is the code I have so far:

writer.WriteAttributeString("xsi", "noNamespaceSchemaLocation", null, "amzn-envelope.xsd");
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");

Now this code outputs this XML element:

<AmazonEnvelope noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

So it's almost there but the xsi: is missing before this noNamespaceSchemaLocation

I really don't know where I'm going wrong.

Also I have been in touch with amazon devs and they tell me that it must be formatted like I have asked. Though if you do some googling you will notice examples of the xml writer code which will output the following XML element:

<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">

This is wrong, and gives an error in the scratch pad.

I hope my question makes sense.

thanks for the help.

When I get tired of fighting the Net Library I just use the simple method : XmlDocument doc = new XmlDocument(); XmlElement amazon = doc.CreateElement("AmazonEnvelope"); amazon.InnerXml = "xsi:noNamespaceSchemaLocation=\"amzn-envelope.xsd\" xmlns:xsi=\"w3.org/2001/XMLSchema-instance\""; doc.AppendChild(amazon);jdweng
@jdweng this doesn't work for my situation. I'm using using (var writer = XmlWriter.Create(stream, settings))Web Dev Guy
Then use : string innerxml = "xsi:noNamespaceSchemaLocation=\"amzn-envelope.xsd\" xmlns:xsi=\"w3.org/2001/XMLSchema-instance\""; using (var writer = XmlWriter.Create(stream, settings)) { writer.WriteStartElement("AmazonEnvelope"); writer.WriteRaw(innerxml); writer.WriteEndElement(); }jdweng