Topic: Get the html code inside an xml tag |
|
---|---|
Author | Thread |
Nervous Wreck (II) Inmate From: Philadelphia, PA. |
posted 07-03-2008 23:13
Hi there! |
Paranoid (IV) Inmate From: Norway |
posted 07-03-2008 23:40
Looks like what you need is to instanciate a new XMLSerializer() and call the serializeToString( node ) method on it with the CODE node as argument, then inject the result into the innerHTML of the destination element. |
Nervous Wreck (II) Inmate From: Philadelphia, PA. |
posted 07-07-2008 06:12
Thanks poi. |
Paranoid (IV) Inmate From: Norway |
posted 07-07-2008 13:24
quote: Oh. Does he have big bones and pointy hair ? |
Nervous Wreck (II) Inmate From: Philadelphia, PA. |
posted 07-07-2008 15:24
We are creating several widgets using the html (xml) that we get from the server, and we need to operate on the html that we thus get. We need to extract out the title and make it as the title of the tool and also we need to extract out the <id> and <dropdowntitle> tag. I tried doing it in html, but then I could not get the innerHTML for the code tag. The ending tag corresponding to the opening code tag moves up and comes right before the first div. To get rid of this we thought of working in xml. |
Paranoid (IV) Inmate From: Norway |
posted 07-07-2008 21:21
Of course it does give you the whole XML's markup since you grab the entire responseText. Here what you need to do to only get the markup of the first CODE node: code: var code = yourXhrObject.responseXML.getElementsByTagName('code'); if( !code || !code.length ) { alert( 'no CODE node' ); return false; } var tempdiv = document.createElement('div'); tempdiv.appendChild( code[0] ); alert(tempdiv.innerHTML); return true; or code: var code = yourXhrObject.responseXML.getElementsByTagName('code'); if( !code || !code.length ) { alert( 'no CODE node' ); return false; } var tempdiv = document.createElement('div'); tempdiv.innerHTML = (new XMLSerializer()).serializeToString( code[0] ) ); Note that the later will also include the markup of the CODE node itself so you'll certainly need to loop through its children, and maybe use a DocumentFragment. |
Paranoid (IV) Inmate From: Norway |
posted 07-08-2008 08:14
correction: Both methods will include the CODE tag itself, so loop through its children at some point. |
Nervous Wreck (II) Inmate From: Philadelphia, PA. |
posted 07-08-2008 20:22
Thanks a lot poi. |
Nervous Wreck (II) Inmate From: Philadelphia, PA. |
posted 07-08-2008 23:04
Now, IE is sucking my blood..., everything is working fine in FF (2.0 as well as 3.0). |
Nervous Wreck (II) Inmate From: Philadelphia, PA. |
posted 07-08-2008 23:08
Update: |
Paranoid (IV) Inmate From: Norway |
posted 07-08-2008 23:12 |
Nervous Wreck (II) Inmate From: Philadelphia, PA. |
posted 07-09-2008 14:48
http://ganymede.library.upenn.edu/cocoon/pennpage/html/librarians/ankit/test.html |