473,322 Members | 1,409 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,322 software developers and data experts.

Javascript: createElementNS not work in IE ?

24
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 9715
sumittyagi
202 Expert 100+
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 Expert Mod 8TB
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
thank you all ! I got it.
Mar 8 '07 #4
acoder
16,027 Expert Mod 8TB
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
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...
0
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...
2
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...
136
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...
3
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...
6
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...
4
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...
4
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...
2
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.