1

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.

3
  • 1
    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); Commented Nov 22, 2017 at 9:37
  • @jdweng this doesn't work for my situation. I'm using using (var writer = XmlWriter.Create(stream, settings)) Commented Nov 22, 2017 at 21:48
  • 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(); } Commented Nov 23, 2017 at 0:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.