Click here to Skip to main content
15,906,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to generate this xml header:

XML
<?xml version="1.0" encoding="UTF-8"?>
<ru:myobject XML_DATA="2.1.0"
    xmlns:ru="http://www.aaa.com" xmlns:t="http://www.bbb.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
http://www.aaa.com aaa.xsd
http://www.bbb.com bbb.xsd
http://www.ccc.com ddd.xsd">


The problem is the namespace in xsi:schemaLocation atribute.

here is my code:
XNamespace mynamespace = "http://www.aaa.com/test/";
XNamespace xsi = "http://www.aaa.com/test/ aaa.xsd http://www.bbb.com bbb.xsd http://www.ccc.com ccc.xsd";
XElement myobject = new XElement(mynamespace + "myobject", new XAttribute("XML_DATA", "2.1.0"));
myobject.Add(new XAttribute(XNamespace.Xmlns + "ru", "http://www.aaa.com"));
myobject.Add(new XAttribute(XNamespace.Xmlns + "t", "http://www.bbb.com"));
myobject.Add(new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"));

myobject.Add(new XAttribute(xsi+"schemaLocation", xsi.ToString()));


It generates this header and I don't know why.

XML
<?xml version="1.0" encoding="UTF-8"?>
<ru:myobject XML_DATA="2.1.0"
xmlns:ru="http://www.aaa.com" xmlns:t="http://www.bbb.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
p3:schemaLocation=" http://www.aaa.com aaa.xsd http://www.bbb.com bbb.xsd http://www.ccc.com ddd.xsd"
xmlns:p3="http://www.aaa.com aaa.xsd http://www.bbb.com bbb.xsd http://www.ccc.com ddd.xsd">



Can anyone help? I'm newbie in xml
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900