WriteXML and xmlns attribute


R

rno

Hi,

I have a dataset in my application that I write to an XML file using
WriteXML. The resulting XML file has a xmlns namespace attribute as
part of the root element.

When I try and create an XSL file to display some data in a browser, I
do not get any output unless I strip out the attribute. (I am very new
to this stuff).

I suppose I could tackle this in two ways:

1. try to make the WriteXML method to omit the namespace attribute
2. create the XSL so that it can cope with it.

I think 2. is not for this newsgroup, so my question is: is it
possible to have WriteXML omit the namespace attribute? Is it wise? It
is my understanding that the namespace is used for disambiguation of
the xml elements, but in my case, I don't need to (I think).

(A third option would be of course to read the XML file back in and
delete it the xmlns attribute, but that does not strike me as a
particularly good practice.)

tia,
arno
 
Ad

Advertisements

M

Martin Honnen

rno said:
I have a dataset in my application that I write to an XML file using
WriteXML. The resulting XML file has a xmlns namespace attribute as
part of the root element.

When I try and create an XSL file to display some data in a browser, I
do not get any output unless I strip out the attribute. (I am very new
to this stuff).

I suppose I could tackle this in two ways:

1. try to make the WriteXML method to omit the namespace attribute
2. create the XSL so that it can cope with it.

I think 2. is not for this newsgroup, so my question is: is it
possible to have WriteXML omit the namespace attribute? Is it wise? It
is my understanding that the namespace is used for disambiguation of
the xml elements, but in my case, I don't need to (I think).
Can you share the code creating and populating the DataSet with data? I
don't think any namespace is the default with WriteXml thus if you want
help to avoid the namespace in the result of WriteXml we first need to
understand why you get XML with a default namespace declaration.

As for dealing with the namespace when writing XSLT to process the XML
see http://www.dpawson.co.uk/xsl/sect2/N5536.html#d7035e187 or ask in
microsoft.public.dotnet.xml showing us the exact XML.
 
R

rno

It's a dataset I created with the designer. Your post triggered me to
have a closer look at it, and in the xsd designer, I cleared the
Namespace property (it was set to http://tempuri.org/myDataset.xsd,
which I believe is default behaviour of the designer), that being the
line I did not want written to the XML.

When I saved it, it screwed up the entire project :( The xsd code is
completely empty now, as well as the corresponding cs file. Out of the
tsunami of error messages, I think this one is the important one:

"Error 74 Custom tool error: Failed to generate code. Unable to
convert input xml file content to a DataSet. There are multiple root
elements. Line 175, position 2." on the myDataset.xsd file. Which has 1
line?!

Until I fooled around with the namespace property in the designer, all
was peachy. So apparently I should not have cleared the Namespace
property, and I am stuck with a broken project now. Would appreciate
some advice on how to sort this out, if possible.

tia
arno
 
R

rno

anyone? Upon re-opening the C#.NET IDE, I can now not even open the
dataset designer anymore, it complains about 'no external editor
available'. All I did was clear the Namespace property in the IDE, so
I am a bit surprised at these grave consequences - the whole project
is effectively <beep>ed.

tia
arno
 
Ad

Advertisements

Joined
Jan 30, 2015
Messages
1
Reaction score
0
yourDataSet.Namespace = String.Empty;
string xmlSheet = yourDataSet.GetXml();
 

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