473,770 Members | 7,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot use a prefix with an empty namespace exception

I'm trying to create an XML document that can be opened in Excel. I have some
simple code that ... eventually does the following

elem = _doc.CreateElem ent("Style");
elem.SetAttribu te("ss:ID","Def ault");
elem.SetAttribu te("ss:Name","N ormal");
parentElem.Appe ndChild(elem);

to add a "Style" item with 2 attributes. My problem is that when I do a
Save on the XML document I get an Attribute exception "Cannot use a prefix
with an empty namespace". So (dumb question I'm sure) but I can't figure out
how to make this work.

I've tried playing with the NamespaceManage r as in the following thinking
that might have to have the prefix set in the namespace first.. no difference.

XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(_doc.NameT able)
nsmgr.AddNamesp ace(String.Empt y,"urn:schema s-microsoft-com:office:spre adsheet");
nsmgr.AddNamesp ace("o","urn:sc hemas-microsoft-com:office:offi ce");
nsmgr.AddNamesp ace("x","urn:sc hemas-microsoft-com:office:exce l");
nsmgr.AddNamesp ace("ss","urn:s chemas-microsoft-com:office:spre adsheet"
); nsmgr.AddNamesp ace("html","htt p://www.w3.org/TR/REC-html40");

Also, I can seem to set the attributes in this way for the document element
node

elem = _doc.CreateElem ent("Workbook") ;
elem.SetAttribu te("xmlns","urn :schemas-microsoft-com:office:spre adsheet");
elem.SetAttribu te("xmlns:o","u rn:schemas-microsoft-com:office:offi ce");
elem.SetAttribu te("xmlns:x","u rn:schemas-microsoft-com:office:exce l");
elem.SetAttribu te("xmlns:ss"," urn:schemas-microsoft-com:office:spre adsheet");
elem.SetAttribu te("xmlns:html" ,"http://www.w3.org/TR/REC-html40");
_doc.AppendChil d(elem);

So, after spending much time looking (and being confused by) what I found in
documentation and online I'm hoping somone can point me to a simple (but
complete) example of how this should be done or can point out what I'm
missing.

Thanks
--
Neil
Nov 12 '05 #1
1 8408


NeilL wrote:
I'm trying to create an XML document that can be opened in Excel. I have some
simple code that ... eventually does the following

elem = _doc.CreateElem ent("Style");
elem.SetAttribu te("ss:ID","Def ault");


You probably want to do the following:
XmlAttribute attribute = doc.CreateAttri bute("ss:ID",
"urn:schema s-microsoft-com:office:spre adsheet");
attribute.Value = "Default";
elem.SetAttribu teNode(attribut e);

That way the attribute is created in the proper namespace.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

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

Similar topics

4
20503
by: Krishna Tulasi via .NET 247 | last post by:
Hi, I am having trouble with creation of XML programmatically using .NET. Specifically Im trying to create an element which looks like below and insert into an existing xml doc: <Worksheet ss:Name="TKCSheet1"> </Worksheet> The existing xml doc is: <?xml version="1.0"?> <?mso-application progid="Excel.Sheet"?>
2
2011
by: Dale Anderson | last post by:
I have a schema that I'm trying to read. The schema has an element named 'GrantApplication' and one with a namespace prefix named 'SF424:GrantApplication'. When I try to read this schema in, I get an exception saying 'A datatable named 'GrantApplication' alread belongs to this dataset'. Why is dotnet not recognizing the namespace prefix and treating these like two separate elements? Thanks for your help.
2
6933
by: PeterW | last post by:
I have an xml file from which I want to generate an xsd schema and at a later stage a cs class. The xml file has a mix of defined namespaces and also an empty namespace. These are defined as follows: <silcn:silcn xmlns:silcn='http://silcn.org/200309' xmlns='http://xmlprobe.com/200312'> it contains an element <report> off the root and also a separate <Silcn:report> again off the root.
6
20823
by: Thea | last post by:
Hi I am trying to use datatypes defined in xml file to check correctness of input parameter values To define needed datatypes following schema.xml file was created: <?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pd="uri:myUri.com"> <xsd:simpleType name="pd:width">
6
2067
by: Chris Chiasson | last post by:
Hi, After reading and experimenting for a several hours, I have this stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xmlns="http://www.w3.org/2000/xmlns/" xmlns:mathematica="http://www.wolfram.com/XML/" version="1.0">
2
21639
by: scottpet | last post by:
Hi, I want to add a namespace prefix to the root node of an object I am serializing to XML. I have been reading though this article: http://msdn2.microsoft.com/en-gb/library/system.xml.serialization.xmlnamespacedeclarationsattribute.aspx I get namespace prefixes in the document, but not on the root node. Specifically, the serializer does not work as described in the last
3
8450
by: Markus Bauer | last post by:
Hello, I have a problem with the namespace prefix. I need to add nodes to a xml file that is not created by me. It has a namespace with the prefix "NFD". So an already existing node looks like that: <NFD:Sonstiger_Hinweis> <NFD:Erfassungsdatum>20070102</NFD:Erfassungsdatum>
3
7888
by: Abhinavnaresh | last post by:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Xml.Xsl.XsltException: Cannot find the script or external object that implements prefix 'counter'. Source Error: An unhandled exception was generated during the execution of the current web request. Information...
2
14404
by: rakeshvthu | last post by:
Hi All, I am trying to parse the xml. <ns1:ProcessGLAccountValidationRequestABM xmlns:ns1="http://xmins.oracle.com/ApplicationObjects/Ebiz/Core/ABM/ChartOfAccounts/V1"> <ns2:ChartOfAccountsName xmlns:ns2="http://xmlns.oracle.com/ApplicationObjects/Ebiz/Core/ABO/ChartOfAccounts/V1">Netherlands Accounting Flex</ns2:ChartOfAccountsName> <ns2:ChartOfAccountsId>50560</ns2:ChartOfAccountsId> <ns2:CodeCombinations> ...
0
10230
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10058
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.