Points of Required Attention™
Please chime in on a proposed restructuring of the ROM hacking sections.
Views: 88,546,569
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search 05-06-24 11:19 AM
Guest: Register | Login

0 users currently in Computing | 1 guest

Main - Computing - Accessing current XML document in Javascript New thread | New reply


HyperHacker
Posted on 06-17-07 09:06 AM Link | Quote | ID: 46244

...
Level: 73

Posts: 872/1220
EXP: 3369486
Next: 116382

Since: 03-25-07
From: no

Last post: 6101 days
Last view: 6085 days
So I have an XML file which links to an XSL stylesheet to make some nice fancy output in my browser, including some Javascript. I want this script to be able to access the original XML file, but it seems like the browser "pretends" the XSL output is the original file, so I can only access the generated HTML. The only way I see to access the XML is to use the HTTPRequest object to download it from the server, and it seems silly to have to download the file a second time just to access it in a script. Google has found me nothing on this subject (obviously).

neotransotaku
Posted on 06-17-07 08:40 PM Link | Quote | ID: 46346


Shyguy
Level: 24

Posts: 17/95
EXP: 73070
Next: 5055

Since: 04-19-07

Last post: 5032 days
Last view: 2915 days
what is in the XML file that you want to alter dynamically? Perhaps there might be another way to go about it?

HyperHacker
Posted on 06-18-07 05:38 AM Link | Quote | ID: 46469

...
Level: 73

Posts: 879/1220
EXP: 3369486
Next: 116382

Since: 03-25-07
From: no

Last post: 6101 days
Last view: 6085 days
I don't want to alter anything. I want to read the data, format it, and output it to a text box.

neotransotaku
Posted on 06-18-07 05:58 AM (rev. 2 of 06-18-07 06:11 AM) Link | Quote | ID: 46472


Shyguy
Level: 24

Posts: 18/95
EXP: 73070
Next: 5055

Since: 04-19-07

Last post: 5032 days
Last view: 2915 days
Perhaps, you can cache the results?

It seems I don't quite remember how you can render and format XML via an XLST.

HyperHacker
Posted on 06-18-07 09:19 AM Link | Quote | ID: 46512

...
Level: 73

Posts: 881/1220
EXP: 3369486
Next: 116382

Since: 03-25-07
From: no

Last post: 6101 days
Last view: 6085 days
That still involves re-downloading the file.

neotransotaku
Posted on 06-18-07 07:00 PM Link | Quote | ID: 46604


Shyguy
Level: 24

Posts: 19/95
EXP: 73070
Next: 5055

Since: 04-19-07

Last post: 5032 days
Last view: 2915 days
Would it be possible to use javascript to initiate the rendering of the XML/XLST?

HyperHacker
Posted on 06-18-07 11:02 PM Link | Quote | ID: 46673

...
Level: 73

Posts: 890/1220
EXP: 3369486
Next: 116382

Since: 03-25-07
From: no

Last post: 6101 days
Last view: 6085 days
I doubt it, because the XSLT is what outputs the script. Also, the script needs to be triggered at the push of a button.

neotransotaku
Posted on 06-19-07 01:02 AM Link | Quote | ID: 46705


Shyguy
Level: 24

Posts: 20/95
EXP: 73070
Next: 5055

Since: 04-19-07

Last post: 5032 days
Last view: 2915 days
What drives the XSLT to process the XML?

HyperHacker
Posted on 06-19-07 01:04 AM Link | Quote | ID: 46707

...
Level: 73

Posts: 894/1220
EXP: 3369486
Next: 116382

Since: 03-25-07
From: no

Last post: 6101 days
Last view: 6085 days
You link to it: <?xml-stylesheet href="../codes.xsl" type="text/xsl"?> and the browser uses it automatically.

neotransotaku
Posted on 06-19-07 02:42 AM Link | Quote | ID: 46728


Shyguy
Level: 24

Posts: 21/95
EXP: 73070
Next: 5055

Since: 04-19-07

Last post: 5032 days
Last view: 2915 days
I came across this. I t appears that if you use javascript to create a XSLT processor, then load your XML (caching it via the other link I showed you), should give you what you want?

HyperHacker
Posted on 06-19-07 02:50 AM Link | Quote | ID: 46731

...
Level: 73

Posts: 895/1220
EXP: 3369486
Next: 116382

Since: 03-25-07
From: no

Last post: 6101 days
Last view: 6085 days
I could do that, but it'd require Javascript to be on to view the page. :-/

neotransotaku
Posted on 06-19-07 03:09 AM Link | Quote | ID: 46734


Shyguy
Level: 24

Posts: 22/95
EXP: 73070
Next: 5055

Since: 04-19-07

Last post: 5032 days
Last view: 2915 days
So, doing >script src="myjavascript.js"<>/script< is not an option? I mean, you said you output javascript using the XSLT...


HyperHacker
Posted on 06-19-07 03:25 AM Link | Quote | ID: 46735

...
Level: 73

Posts: 896/1220
EXP: 3369486
Next: 116382

Since: 03-25-07
From: no

Last post: 6101 days
Last view: 6085 days
I think one of us is confused. When you access the .xml file in the browser it loads the XSL file, which tells it what to output. Javascript can be part of that output, but I need some way for that Javascript to read the XML file itself and there doesn't seem to be any way to do that. Your idea seemed to be that the user accesses a plain HTML page which then uses Javascript to download the XML/XSL files, which means without Javascript they won't see anything.

The only way I can see to make that work is to have an index page listing the XML files, and use an onclick handler on the links to download and parse the XML file. If Javascript were disabled the link would lead directly to the XML file like normal. However, this has some problems I can see right away:

  • It'd be a pain in the ass to code.
  • If Javascript were on then you wouldn't actually leave the index page, so you couldn't bookmark/link externally to the XML files and Back would go back to the page before it.
  • It may still not be possible for the script that loads the XML file to pass info to the script that the XSL file produces.
  • There's gotta be some way to read the original XML...

neotransotaku
Posted on 06-19-07 09:10 AM (rev. 2 of 06-19-07 09:10 AM) Link | Quote | ID: 46806


Shyguy
Level: 24

Posts: 23/95
EXP: 73070
Next: 5055

Since: 04-19-07

Last post: 5032 days
Last view: 2915 days
If this doesn't do what you want it to do, then you need to write a web service or something.

All the code taken from those two sites I gave links to and I pulled a random XML/XSLT off the internet.

- It wasn't too bad to code--I only need to lookup how I can pass stuff to the XML stuff
- Bookmarking issues, try Bookmarklets
- Javascript has a root environment across all script tags. You just need a global place to pass information.
- See example

HyperHacker
Posted on 06-19-07 09:54 AM Link | Quote | ID: 46812

...
Level: 73

Posts: 899/1220
EXP: 3369486
Next: 116382

Since: 03-25-07
From: no

Last post: 6101 days
Last view: 6085 days
No, see, you're linking to an HTML page that uses Javascript to download an XML file. I'm linking directly to the XML file and having the XSL stylesheet output Javascript which needs to read the XML file it was generated from. Not download a file.

You go to foo.xml which links to bar.xsl which produces some nice fancy HTML for the browser to render. Within that HTML is some Javascript code. This code needs to be able to read foo.xml, not the nice fancy HTML, without having to download it a second time. Got it?

neotransotaku
Posted on 06-19-07 05:18 PM Link | Quote | ID: 46881


Shyguy
Level: 24

Posts: 24/95
EXP: 73070
Next: 5055

Since: 04-19-07

Last post: 5032 days
Last view: 2915 days
In short, you don't want to have an extra layer, which is what my solution is doing.

(1) XLST loaded directly
(2) Ajax reads XML
(3) XML text and XML DOM saved
(4) XLST applied to XML to generate HTML
(5) That HTML has access to the XML text and XML DOM

If I understand correctly, you want steps 4 and 5 without 1-3. That solution still loads the XML once. Oh well, I have offered a potential solution. Sorry for not satisfying your requirements.

stag019
Posted on 06-19-07 06:22 PM (rev. 2 of 06-19-07 07:31 PM) Link | Quote | ID: 46889


Snifit
Level: 40

Posts: 121/299
EXP: 409922
Next: 31387

Since: 02-19-07

Last post: 4290 days
Last view: 2176 days
I have no clue for any other browsers, but in IE, you seem to be able to access it with document.XMLDocument.

Or, for IE, the content itself is in document.XMLDocument.xml.

So, what you would want to do is put something like this in the XSL stylesheet (again, only works in IE)?
if(document.XMLDocument)
{
body = document.body;
cloneBody = body.cloneNode(false);
body.parentNode.insertBefore(cloneBody, body);
body.parentNode.removeChild(body);
pre = document.createElement('pre');
pre.style.wordWrap = 'break-word';
pre.appendChild(document.createTextNode(document.XMLDocument.xml));
document.body.appendChild(pre);
}


Edit: Apparently, in Firefox, there is no way to access it with javascript. It suggest using view-source: if you wanna just view the XML source, though.

Still no idea for any other browsers.

neotransotaku
Posted on 06-19-07 07:51 PM Link | Quote | ID: 46907


Shyguy
Level: 24

Posts: 25/95
EXP: 73070
Next: 5055

Since: 04-19-07

Last post: 5032 days
Last view: 2915 days
Interesting, it is a 5 year old feature request which doesn't seem it will ever be implemented. But, I guess HH can try <xsl:copy-of select="/"/>.

HyperHacker
Posted on 06-19-07 11:00 PM Link | Quote | ID: 46979

...
Level: 73

Posts: 903/1220
EXP: 3369486
Next: 116382

Since: 03-25-07
From: no

Last post: 6101 days
Last view: 6085 days
That seems terribly inefficient... I guess I'll have to redownload it, it's looking like Javascript may end up being required anyway.

Main - Computing - Accessing current XML document in Javascript New thread | New reply

Acmlmboard 2.1+4δ (2023-01-15)
© 2005-2023 Acmlm, blackhole89, Xkeeper et al.

Page rendered in 0.025 seconds. (321KB of memory used)
MySQL - queries: 82, rows: 109/110, time: 0.016 seconds.