Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: What XMLHttpRequest.responseXML good for (in XHTML)?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What XMLHttpRequest.responseXML good for (in XHTML)?



I do not want HTML. My "parent" document is XHTML, the document I am loading is XHTML. All I want is been able to do appendChild() on one of the nodes of "parent" document with one of the nodes of the document I have loaded.

Anyhow, by now, I am quite sure that there is a bug in Safari. So I give up on the whole idea of using XHTML and proceed with alternative implementation.


On Oct 5, 2006, at 5:54 PM, Ⓙⓐⓚⓔ Wolpert wrote:

So far what you have gotten is what is expected! you need to run through the entire dom to find what you are looking for ... unless you have a cool library like jQuery or an id for each element you need.

Here is a snippet from some old code(obj2coloredHTML) that converts a dom object to html. Not my current style, but it still works!
-------------------
var nodeType = ["0","ELEMENT_NODE", "ATTRIBUTE_NODE", "TEXT_NODE", "CDATA_SECTION_NODE",
"ENTITY_REFERENCE_NODE", "ENTITY_NODE", "PROCESSING_INSTRUCTION_NODE", "COMMENT_NODE", "DOCUMENT_NODE",
"DOCUMENT_TYPE_NODE", "DOCUMENT_FRAGMENT_NODE", "NOTATION_NODE"];
var nodeTypeConst = {};
for (var nodeIndex in nodeType) {
nodeTypeConst[nodeType[nodeIndex]] = nodeIndex;
}
function spanClass(cl,text,title) {
if (text=="") return "";
return '<span class="' + cl + '"' + (title ? ' title= "' + title + '"' : '') + '>' + text + "</span>";
}
function obj2coloredHTML(obj) { return "\n<pre>" + o2c_recursive (obj)+"\n\n</pre>";}
function o2c_recursive(obj) { // dump the object back to html
var res = "";
var t = typeof obj;
if (t.match(/string|number|boolean/)) {
return obj;
} else if (t.match(/object|function/)) {
var tag = obj.nodeName;
var showTheTag = obj.nodeName.charAt(0) != "#";
var title = (obj.namespaceURI ? 'NS:' + obj.namespaceURI : '' );
if (obj.nodeType ==nodeTypeConst.DOCUMENT_TYPE_NODE) return "";
if (obj.nodeType ==nodeTypeConst.PROCESSING_INSTRUCTION_NODE)
return spanClass('pi',"&lt;?" + tag + " " + obj.nodeValue + "?> \n") ;
tag = tag.toLowerCase(); // dom nodeName are in uppercase. By this point, I want lower.
if (obj.processingInstruction) return spanClass('pi',"&lt;?" + obj.processingInstruction.target + " " + obj.processingInstruction.data + "?>"); // nope!
if (showTheTag) res += spanClass('tag','&lt;' + tag,title);
if (obj.hasAttributes && obj.hasAttributes()) {
var attrs = obj.attributes;
for (var i = 0; i < attrs.length; i++){
var attr=attrs[i];
if (attr.specified) res +=' ' + spanClass ('attr',attr.name.toLowerCase()) + spanClass('string','="' + attr.value + '"');
}
}
var nv = obj.nodeValue ? obj.nodeValue :'';
var barren = obj.hasChildNodes && !obj.hasChildNodes();
if (showTheTag) res+=barren ? " />" : spanClass('tag',">");
if (obj.nodeType == nodeTypeConst.COMMENT_NODE){
res += spanClass('comment',"&lt;!-- " + obj.nodeValue + " -->");
} else {
res += spanClass("",nv);
}
if (obj.hasChildNodes && obj.hasChildNodes()) {
var children = obj.childNodes;
for (var i = 0; i < children.length; i++){
var child = children[i];
res += o2c_recursive(child);
}
}
if (!barren && showTheTag) res += spanClass('tag','&lt;/' + tag + '>',title);
} else {
return ("other type:" + typeof obj) + ":" + obj;
}
return res;


}


Ⓙⓐⓚⓔ - יעקב ʝǡǩȩ ᎫᎪᏦᎬ ▒░▒░▒░▒░▒░▒░▒░▒░▒░▒░▒░▒ ░▒░▒░▒░▒░▒░▒░▒░▒░▒░▒░▒░ ▒░▒░▒░▒░▒░▒░▒░▒░▒░▒░▒░▒ ░▒░▒░▒░▒░▒░▒░▒░▒░▒░▒░▒░ ▒░▒░▒░▒░▒░▒░▒░▒░▒░▒░▒░▒

email@hidden



On Oct 5, 2006, at 1:43 PM, Andrei Tchijov wrote:

John,
Response is not empty and xhtml.documentElement.getElementsByTagName( "body" ) returns an array of 1 element and this element is "body". And body.firstChild returns an element which is #text. and it has not null nextSibling which is happen to be an Element ('h1' in my particular case). And as soon as script trying to appendChild with this element - Safari blow.


Andrei

On Oct 5, 2006, at 4:31 PM, John Jameson wrote:

Hi Andrei,

You need to check that responseXML is not empty. If the MIME type of the
response is not text/xml then the content will be in responseText.


HTH.

Regards,

John Jameson.


Message: 2 Date: Wed, 4 Oct 2006 19:53:01 -0400 From: Andrei Tchijov <email@hidden> Subject: What XMLHttpRequest.responseXML good for (in XHTML)? To: Apple Web Dev list <email@hidden> Message-ID: <email@hidden> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed

I am using some AJAX (via prototype.js ) to get content of XHTML
file. AJAX works perfectly. I am getting wonderful XML which looks/
sounds/smells like DOM XML representing my XHTML page. The problem it
that every time I am trying to "move" nodes from XML which I got via
AJAX to my XHTML page DOM, Safari crash. These are relevant bits of
my code:


...
function importXHTML( url ) {
var myAjax = new Ajax.Request( url, { method: 'get', asynchronous:
false });
if( myAjax.transport.status != 200 ) {
return null;
}
return myAjax.transport.responseXML;
}
...
var xhtml = importXHTML( fullHref );


var bodyElement = xhtml.documentElement.getElementsByTagName ( "body" )
[0];
var nextChild = bodyElement.firstChild;


while( nextChild ) {
    target.appendChild( nextChild );
    nextChild = nextChild.nextSibling;
}
...

To be precise, Safari crash trying to "appendChild" first element
node (the very first node happen to be #text and it does not case any
problems ).


Am I doing something illegal?  The very same code works happily on
Firefox.

Your comments will be highly appreciated,

Andrei Tchijov
Leaping Bytes, LLC


_______________________________________________ Do not post admin requests to the list. They will be ignored. Web-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Web-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Web-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: What XMLHttpRequest.responseXML good for (in XHTML)? (From: John Jameson <email@hidden>)
 >Re: What XMLHttpRequest.responseXML good for (in XHTML)? (From: Andrei Tchijov <email@hidden>)
 >Re: What XMLHttpRequest.responseXML good for (in XHTML)? (From: Ⓙⓐⓚⓔ Wolpert <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.