XML: empty namespace?

B

BLUE

<GTM.Data:GRTMData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:GTM.Data="http://www.pippo.com/GTMData"
xsi:schemaLocation="http://www.pippo.com/GRTMData GTMDataSchema.xsd">

w.WriteStartElement("GTM.Data","GRTMData","");
w.WriteAttributeString("xmlns","xsi",
null,"http://www.w3.org/2001/XMLSchema-instance");
w.WriteAttributeString("xmlns","GTM.Data",null,"http://www.pippo.com/GRTMData");
w.WriteAttributeString("xsi","schemaLocation",null,"http://www.pippo.com/GTMData
GTMDataSchema.xsd");

Exception: "Cannot use a prefix with an empty namespace".

Why?



Thanks,
Luigi.
 
M

Martin Honnen

BLUE said:
<GTM.Data:GRTMData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:GTM.Data="http://www.pippo.com/GTMData"
xsi:schemaLocation="http://www.pippo.com/GRTMData GTMDataSchema.xsd">

w.WriteStartElement("GTM.Data","GRTMData","");
w.WriteAttributeString("xmlns","xsi",
null,"http://www.w3.org/2001/XMLSchema-instance");
w.WriteAttributeString("xmlns","GTM.Data",null,"http://www.pippo.com/GRTMData");
w.WriteAttributeString("xsi","schemaLocation",null,"http://www.pippo.com/GTMData
GTMDataSchema.xsd");

Exception: "Cannot use a prefix with an empty namespace".

The element has a namespace. And you do not need to write out xmlns
declarations, the serializer will add them automatically once you write
out elements or attributes in a certain namespace. So this suffices:

const string xsi = "http://www.w3.org/2001/XMLSchema-instance";
const string gtm = "http://www.pippo.com/GTMData";

w.WriteStartElement("GTM.Data","GRTMData",gtm);
w.WriteAttributeString("xsi","schemaLocation",xsi,
"http://www.pippo.com/GTMData GTMDataSchema.xsd");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top