| |||
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 |
| ||
... 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 |
| ||
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 |
| ||
... 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 |
| ||
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 |
| ||
... 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 |
| ||
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 |
| ||
... 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 |
| ||
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 |
| ||
... 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 |
| ||
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 |
| ||
... 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 |
| ||
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 |
| ||
... 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:
|
neotransotaku |
| ||
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 |
| ||
... 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 |
| ||
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 |
| ||
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) 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 |
| ||
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 |
| ||
... 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 |
© 2005-2023 Acmlm, blackhole89, Xkeeper et al. |
MySQL - queries: 82, rows: 109/110, time: 0.016 seconds. |