473,549 Members | 2,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript: createElementNS not work in IE ?

24 New Member
The following code catch an exception in IE, with number -2146827850

Expand|Select|Wrap|Line Numbers
  1.             var xmldoc=XmlDocument.create("1str","2str");
  2.             xmldoc.documentElement.setAttribute('code',code);
  3.             var node;
  4.             try{
  5.                  node=xmldoc.createElementNS('urn', 'condition');
  6.             }catch(e)
  7.             { }
It seems that IE dosn't implement createElementNS function. Is there any way to work around it?

I need your help!
Mar 8 '07 #1
4 9728
sumittyagi
202 Recognized Expert New Member
The following code catch an exception in IE, with number -2146827850

Expand|Select|Wrap|Line Numbers
  1.             var xmldoc=XmlDocument.create("1str","2str");
  2.             xmldoc.documentElement.setAttribute('code',code);
  3.             var node;
  4.             try{
  5.                  node=xmldoc.createElementNS('urn', 'condition');
  6.             }catch(e)
  7.             { }
It seems that IE dosn't implement createElementNS function. Is there any way to work around it?

I need your help!

I don't know what you are talking about. I havn't heard about createElementNS function. But if you want to parse xml text, then refer to the code below. Hope it helps.

Expand|Select|Wrap|Line Numbers
  1. 1    /**
  2. 2     * Create a new Document object. If no arguments are specified,
  3. 3     * the document will be empty. If a root tag is specified, the document
  4. 4     * will contain that single root tag. If the root tag has a namespace
  5. 5     * prefix, the second argument must specify the URL that identifies the
  6. 6     * namespace.
  7. 7     */ 
  8. 8    XML.newDocument = function(rootTagName, namespaceURL) { 
  9. 9      if (!rootTagName) rootTagName = ""; 
  10. 10      if (!namespaceURL) namespaceURL = ""; 
  11. 11      if (document.implementation && document.implementation.createDocument) { 
  12. 12        // This is the W3C standard way to do it 
  13. 13        return document.implementation.createDocument(namespaceURL, rootTagName, null); 
  14. 14      } 
  15. 15      else { // This is the IE way to do it 
  16. 16        // Create an empty document as an ActiveX object 
  17. 17        // If there is no root element, this is all we have to do 
  18. 18        var doc = new ActiveXObject("MSXML2.DOMDocument"); 
  19. 19        // If there is a root tag, initialize the document 
  20. 20        if (rootTagName) { 
  21. 21          // Look for a namespace prefix 
  22. 22          var prefix = ""; 
  23. 23          var tagname = rootTagName; 
  24. 24          var p = rootTagName.indexOf(':'); 
  25. 25          if (p != -1) { 
  26. 26            prefix = rootTagName.substring(0, p); 
  27. 27            tagname = rootTagName.substring(p+1); 
  28. 28          } 
  29. 29          // If we have a namespace, we must have a namespace prefix 
  30. 30          // If we don't have a namespace, we discard any prefix 
  31. 31          if (namespaceURL) { 
  32. 32            if (!prefix) prefix = "a0"; // What Firefox uses 
  33. 33          } 
  34. 34          else prefix = ""; 
  35. 35          // Create the root element (with optional namespace) as a 
  36. 36          // string of text 
  37. 37          var text = "<" + (prefix?(prefix+":"):"") +  tagname + 
  38. 38              (namespaceURL 
  39. 39               ?(" xmlns:" + prefix + '="' + namespaceURL +'"') 
  40. 40               :"") + 
  41. 41              "/>"; 
  42. 42          // And parse that text into the empty document 
  43. 43          doc.loadXML(text); 
  44. 44        } 
  45. 45        return doc; 
  46. 46      } 
  47. 47    };
  48.  
Mar 8 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
createElementNS does exist. IE doesn't support it because it can't deal with XHTML properly. Use createElement instead for IE. See this link.
Mar 8 '07 #3
mentor
24 New Member
thank you all ! I got it.
Mar 8 '07 #4
acoder
16,027 Recognized Expert Moderator MVP
No problem. You're welcome.
Mar 8 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
15043
by: Mike Kamermans | last post by:
I'm trying to determine where inside an XHTML's DOM a javascript function is triggered, but when I use the construction of calling a function with "this" as parameter and then checking the event target inside the javascript function, I get very very little love from javascript in an XHTML setting.... I have put up the file that demonstrates my...
0
1203
by: Nicolas VanOrton | last post by:
Hi all, When XercesDOMParser parses an XML document in a file, if a Schema is attached, it automatically adds all attributes with default values to the corresponding nodes... I'm trying to obtain the above behavior when adding nodes with createElementNS but I cannot do so. No default attributes are automatically added. Shouldn't it be...
2
1787
by: Eric Sessoms | last post by:
I am trying to create forms on the fly in strict xhtml using javascript. I won't bore you with why, but I should mention that I'm only interested in the very latest versions of Mozilla based browsers. The basic problem is that the forms do not display. I've included a minimal sample below that illustrates this. It validates, I get no...
136
9223
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to...
3
1655
by: BakedBean | last post by:
Hi, This is probably really simple, but I've only just been asked to look at this and I've spent a full day trying to get it to work, so any help will be very gratefully received! At present I have an HTML page which calls a series of javascript functions which output text into a browser. A client then asked if it was possible to output...
6
5571
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an object collection and stanrd using it it starts to fall apart. Clearly there is something about javascript's usage of passing "By ref" that i am not...
4
5215
by: E | last post by:
I am having trouble with setTimeout working on a second call to the setTimeout function from a second page which is an html page. Here is the scenario. I have a web page and onload it calls a javascript function which calls setTimeout and will process a second javascript function "Warn" just before the session expires. The Warn...
4
9061
by: praskuma | last post by:
Hi All document.createElementNS works fine on firefox, but not on IE. I use this fuction to create SVG objects on the fly for example..... SVG.ns = "http://www.w3.org/2000/svg"; var svg = document.createElementNS(SVG.ns, "svg:svg");
2
2202
by: Holger Jeromin | last post by:
Hello, i need to add SVG things direct in a Website. I know XHTML is best used for that, with works nice in Firefox and Opera. Internet Explorer is more challenging... I have ported my XHTML example to HTML. I am able to manipulate the CSS in my Adobe SVG-Viewer 3 via Javascript.
0
7541
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7734
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. ...
0
7979
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...
0
7826
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...
0
6065
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...
0
3493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1960
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
0
781
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.