3 Modification information for LGPL compliance
5 r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync
7 r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover
9 r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex
11 r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3 tags and updated the build system
13 r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
15 r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
17 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
19 r4085 - 2005-04-13 17:30:42 -0700 (Wed, 13 Apr 2005) - robert - adding meeting scheduler and accept/decline
25 Copyright (c) 2003 Jan-Klaas Kollhof
27 This file is part of the JavaScript o lait library(jsolait).
29 jsolait is free software; you can redistribute it and/or modify
30 it under the terms of the GNU Lesser General Public License as published by
31 the Free Software Foundation; either version 2.1 of the License, or
32 (at your option) any later version.
34 This software is distributed in the hope that it will be useful,
35 but WITHOUT ANY WARRANTY; without even the implied warranty of
36 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 GNU Lesser General Public License for more details.
39 You should have received a copy of the GNU Lesser General Public License
40 along with this software; if not, write to the Free Software
41 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
46 Provides parseXML and an importNode implementation.
48 Module("xml","1.1.2", function(mod){
50 Thrown if no parser could be instanciated.
52 mod.NoXMLParser=Class("NoXMLParser", mod.Exception, function(publ, supr){
54 Initializes the Exception.
55 @param trace The error causing the Exception.
57 publ.init=function(trace){
58 supr(this).init("Could not create an XML parser.", trace);
62 Thrown if a document could not be parsed.
64 mod.ParsingFailed=Class("ParsingFailed", mod.Exception, function(publ, supr){
66 Initializes the Exception.
67 @param xml The xml source which could not be parsed.
68 @param trace The error causing this Exception.
70 publ.init=function(xml,trace){
71 supr(this).init("Failed parsing XML document.",trace);
74 ///The xml source which could not be parsed.
78 Parses an xml document.
79 @param xml The xml text.
80 @return A DOM of the xml document.
82 mod.parseXML=function(xml){
88 try{//to get Adobe's SVG parseXML
89 var p=window.parseXML;
91 throw "No ASV paseXML";
95 try{//to get the mozilla parser
96 obj = new DOMParser();
99 try{//to get the MS XML parser
100 obj = new ActiveXObject("Msxml2.DomDocument.4.0");
103 try{//to get the MS XML parser
104 obj = new ActiveXObject("Msxml2.DomDocument");
107 try{//to get the old MS XML parser
108 obj = new ActiveXObject("microsoft.XMLDOM");
111 throw new mod.NoXMLParser(e);
119 obj = obj.parseFromString(xml, "text/xml");
125 return window.parseXML(xml, null);
128 throw new mod.ParsingFailed(xml,e);
132 DOM2 implimentation of document.importNode().
133 This will import into the current document. In SVG it will create SVG nodes in HTML it will create HTML nodes....
134 This might become customizable in the future.
135 @param importedNode The node to import.
136 @param deep=true Import all childNodes recursively.
137 @return The imported Node.
139 mod.importNode=function(importedNode, deep){
140 deep = (deep==null) ? true : deep;
141 //constants from doom2
142 var ELEMENT_NODE = 1;
143 var ATTRIBUTE_NODE = 2;
145 var CDATA_SECTION_NODE = 4;
146 var ENTITY_REFERENCE_NODE = 5;
148 var PROCESSING_INSTRUCTION_NODE = 7;
149 var COMMENT_NODE = 8;
150 var DOCUMENT_NODE = 9;
151 var DOCUMENT_TYPE_NODE = 10;
152 var DOCUMENT_FRAGMENT_NODE = 11;
153 var NOTATION_NODE = 12;
154 var importChildren=function(srcNode, parent){
156 for(var i=0; i<srcNode.childNodes.length; i++){
157 var n=mod.importNode(srcNode.childNodes.item(i), true);
158 parent.appendChild(n);
163 switch(importedNode.nodeType){
165 node=document.createAttributeNS(importedNode.namespaceURI, importedNode.nodeName);
166 node.value=importedNode.value;
168 case DOCUMENT_FRAGMENT_NODE:
169 node=document.createDocumentFragment();
170 importChildren(importedNode,node);
173 node=document.createElementNS(importedNode.namespaceURI, importedNode.tagName);
174 //import all attributes
175 for(var i=0; i<importedNode.attributes.length; i++){
176 var attr=this.importNode(importedNode.attributes.item(i), deep);
177 node.setAttributeNodeNS(attr);
179 importChildren(importedNode,node);
181 case ENTITY_REFERENCE_NODE:
184 case PROCESSING_INSTRUCTION_NODE:
185 node=document.createProcessingInstruction(importedNode.target, importedNode.data);
188 case CDATA_SECTION_NODE:
190 node=document.createTextNode(importedNode.nodeValue);
193 //Document nodes cannot be imported.
194 case DOCUMENT_TYPE_NODE:
195 //DocumentType nodes cannot be imported.
200 throw "not supported in DOM2";
206 Turns an XML document into a String.
207 @param node The node to print.
208 @return A string containing the text for the XML.
210 mod.node2XML = function(node){
211 var ELEMENT_NODE = 1;
212 var ATTRIBUTE_NODE = 2;
214 var CDATA_SECTION_NODE = 4;
215 var ENTITY_REFERENCE_NODE = 5;
217 var PROCESSING_INSTRUCTION_NODE = 7;
218 var COMMENT_NODE = 8;
219 var DOCUMENT_NODE = 9;
220 var DOCUMENT_TYPE_NODE = 10;
221 var DOCUMENT_FRAGMENT_NODE = 11;
222 var NOTATION_NODE = 12;
224 switch(node.nodeType){
226 s+=node.nodeName+'="' + node.value + '"';
229 s+=this.node2XML(node.documentElement);
232 s+="<" + node.tagName;
234 for(var i=0; i<node.attributes.length; i++){
235 s+=" " + this.node2XML(node.attributes.item(i));
238 if(node.childNodes.length==0){
242 for(var i=0; i<node.childNodes.length; i++){
243 s+=this.node2XML(node.childNodes.item(i));
245 s+="</" + node.tagName+ ">\n";
248 case PROCESSING_INSTRUCTION_NODE:
249 s+="<?" + node.target + " " + node.data + " ?>";
254 case CDATA_SECTION_NODE:
255 s+="<" +"![CDATA[" + node.nodeValue + "]" + "]>";
258 s+="<!--" + node.nodeValue + "-->";
260 case ENTITY_REFERENCE_NODE:
261 case DOCUMENT_FRAGMENT_NODE:
262 case DOCUMENT_TYPE_NODE:
265 throw new mod.Exception("Nodetype(%s) not supported.".format(node.nodeType));