0

I have a xml and I want to add

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../test/Schemas/test.xsd"

to xml root element programmatically in c# so that the xml looks like below.

<?xml version="1.0" encoding="utf-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="../../../../test/Schemas/test.xsd" >
<value></value>
.
.

<root>

what I tried

doc.DocumentElement.SetAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance"); doc.DocumentElement.SetAttribute("xsi:noNamespaceSchemaLocation="../../../../test/Schemas/test.xsd");

1
  • 1
    This may possibly help to explain. Commented Mar 22, 2016 at 5:23

1 Answer 1

0

One possible solution is to create the xsi attribute using the CreateAttribute method and then adding this attribute to the root element like:

XmlAttribute xsiAttr = doc.CreateAttribute("xsi", "noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
xsiAttr.Value = "../../../../test/Schemas/test.xsd";
doc.DocumentElement.Attributes.Append(xsiAttr);
Sign up to request clarification or add additional context in comments.

Comments

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.