473,224 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

Writing xmlns using WriteAttributeString

I am trying to create an XML spreadsheet for use with Excel. I first saved a
simple spreadsheet as an XML file, and now I am trying to recreate that file
in code, using .NET 2.0. The beginning of the XML file should look like the
following:

<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">

I can create all of this except for the first xmlns attribute in the
Workbook element. Here is my code:

writer.WriteStartDocument();
writer.WriteWhitespace("\n");
writer.WriteRaw("<?mso-application progid=\"Excel.Sheet\"?>");
writer.WriteWhitespace("\n");
Writer.WriteStartElement("Workbook");
writer.WriteAttributeString("xmlns",
"urn:schemas-microsoft-com:office:spreadsheet");
writer.WriteAttributeString("xmlns", "o", null,
"urn:schemas-microsoft-com:office:office");
writer.WriteAttributeString("xmlns", "x", null,
"urn:schemas-microsoft-com:office:excel");
writer.WriteAttributeString("xmlns", "ss", null,
"urn:schemas-microsoft-com:office:spreadsheet");
writer.WriteAttributeString("xmlns", "html", null,
"http://www.w3.org/TR/REC-html40");
writer.WriteEndElement();

When the code gets to the first WriteAttributeString statement, it gives an
error "The prefix '' cannot be redefined to
'urn:schemas-microsoft-com:office:spreadsheet' within the same start element
tag." If I comment out that line, it works fine, minus the first attribute,
or course. I have tried every permutation I can think of for every oveload to
write an xmlns attribute withoug a local name, to no avail.

Any suggestions?

Thanks.
Dan


Jul 31 '06 #1
3 11142


dhurwitz wrote:

<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
writer.WriteRaw("<?mso-application progid=\"Excel.Sheet\"?>");
That is a processing instruction so no need to force something with
WriteRaw, doing
writer.WriteProcessingInstruction("mso-application",
"progid=\"Excel.Sheet\"");
should suffice.

Writer.WriteStartElement("Workbook");
writer.WriteAttributeString("xmlns",
"urn:schemas-microsoft-com:office:spreadsheet");
Write the element in the proper namespace, there is no need to
explicitly write an xmlns declaration, doing
writer.WriteStartElement("Workbook",
"urn:schemas-microsoft-com:office:spreadsheet");
suffices to have the writer add the xmlns declaration automatically.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jul 31 '06 #2
Thank you. That is very helpful.

--Dan

"Martin Honnen" wrote:
>

dhurwitz wrote:

<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"

writer.WriteRaw("<?mso-application progid=\"Excel.Sheet\"?>");

That is a processing instruction so no need to force something with
WriteRaw, doing
writer.WriteProcessingInstruction("mso-application",
"progid=\"Excel.Sheet\"");
should suffice.

Writer.WriteStartElement("Workbook");
writer.WriteAttributeString("xmlns",
"urn:schemas-microsoft-com:office:spreadsheet");

Write the element in the proper namespace, there is no need to
explicitly write an xmlns declaration, doing
writer.WriteStartElement("Workbook",
"urn:schemas-microsoft-com:office:spreadsheet");
suffices to have the writer add the xmlns declaration automatically.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jul 31 '06 #3

"dhurwitz" <dh******@discussions.microsoft.comwrote in message
news:E8**********************************@microsof t.com...
Also I find it better to use the indent property of the writer, rather than
writing loads of whilespace newlines manually.
Thank you. That is very helpful.

--Dan

"Martin Honnen" wrote:
>>

dhurwitz wrote:

<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"

writer.WriteRaw("<?mso-application progid=\"Excel.Sheet\"?>");

That is a processing instruction so no need to force something with
WriteRaw, doing
writer.WriteProcessingInstruction("mso-application",
"progid=\"Excel.Sheet\"");
should suffice.

Writer.WriteStartElement("Workbook");
writer.WriteAttributeString("xmlns",
"urn:schemas-microsoft-com:office:spreadsheet");

Write the element in the proper namespace, there is no need to
explicitly write an xmlns declaration, doing
writer.WriteStartElement("Workbook",
"urn:schemas-microsoft-com:office:spreadsheet");
suffices to have the writer add the xmlns declaration automatically.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: JemPower | last post by:
Hi, I've created a routine that reads from my sql server and outputs the contents to an XML file. I have two problems. Firstly, if an error occurs (i.e. the user doesn't supply the correct...
4
by: vikas | last post by:
Hi I want to create following xml document using xmlwriter <?xml version="1.0" ?> - <epps> - <remit_trn type="technical"> <remit_date_dtm dtm = "201" >test</remit_date_dtm>...
3
by: Abdessamad Belangour | last post by:
Hi all, I have developped an application that generate XML documents. At most time it works fine, but sometimes (when the size of data to export is big) i got the error message : << The...
2
by: Mori | last post by:
I am using the following code to manufactue xml using xmltextwriter. The xml is okay except for the extra set of start document and the outer <string> element. Where do they come from and how do...
8
by: Marc Gravell | last post by:
I want to write a method that will accept a stream as a parameter, and which will write xml to the stream (based in reality on database results) using the XmlTextWriter class. However, this insists...
4
by: Paul Hadfield | last post by:
Hi, Wonder if anyone can help me on this, In DotNet2.0 I've been quite happily using the WriteAttributeString method of XmlWriter object, but have run into a problem when trying to output a...
1
by: remya1000 | last post by:
i'm using VB.NET and Microsoft Access. and in one of my Access table is called Emp.mdb. and in that Emp.mdb i have lots of tables like MD1, MD2,......MD58 and MB1,MB2,......MB67 and some other...
12
by: G.S. | last post by:
Is it acceptable to use { } blocks to improve readability and maintainability of the code? Example: //add the checkbox column DataGridViewCheckBoxColumn column = new...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.