Copy link to clipboard
Copied
Hello,
I am attempting to write a little floater extension that will show some data from one of our internal servers. I need to call a REST service from the extension, parse the XML and display the result. Note this does nothing to the currently open document or anything else, its just a helpful little status window that happens to be in DW.
I have the UI, I have the call and now I need the parse and display bit.
One thing that would be handy, and I have not been able to discern from the docs, is to have a list of APIs that are available to the JS. I see some of the very specific stuff - like extra events on the BODY tag, but nothing that says "write javascript and HTML like you are in FF3 and you will be good to go". So how do I know what services are available to be used by my JS code? The examples are a great starting point, but I need some slightly more detailed JS code to get to where I need to be.
Any help is greatly appreciated.
Thanks,
Judd
Copy link to clipboard
Copied
Judd,
I am attempting to write a little floater extension that will show some data from one of our internal servers. I need to call a REST service from the extension, parse the XML and display the result. Note this does nothing to the currently open document or anything else, its just a helpful little status window that happens to be in DW.
I have the UI, I have the call and now I need the parse and display bit.
One thing that would be handy, and I have not been able to discern from the docs, is to have a list of APIs that are available to the JS. I see some of the very specific stuff - like extra events on the BODY tag, but nothing that says "write javascript and HTML like you are in FF3 and you will be good to go". So how do I know what services are available to be used by my JS code? The examples are a great starting point, but I need some slightly more detailed JS code to get to where I need to be.
You should be able to use dw.getDocumentDOM() to do the parsing. If you pass in a file with a .xml file extension, it parses the file as XML. For example:
xmlDom = dw.getDocumentDOM("data.xml");
Then you can get the info you need from the DOM. Does that help?
HTH,
Randy
Copy link to clipboard
Copied
Hi Randy,
What if I get the file from a server URL? I am making a REST call and want
to parse the result. So there is really only a string. We did some wacky
workarounds to get that to work, I am hoping that I can just use something
that is purpose built to deal with the XML string.
Any ideas?
I will post our code later today so you can see it - its not pretty.
-Judd
Copy link to clipboard
Copied
What if I get the file from a server URL? I am making a REST call and want
to parse the result. So there is really only a string.
Any ideas?
Start by opening a known, empty XML file (that you'll need to create) like this:
xmlDom = dw.getDocumentDOM("empty.xml");
This establishes that the parsing format is XML, and creates a DOM for you. Then set it's contents to be your string of XML markup like this:
xmlDOM.documentElement.outerHTML = xmlData;
That will cause the DOM to be rebuilt using the new markup.
If you search the Configuration folder, you'll find examples of this technique for HTML using the "/Shared/MM/Cache/empty.htm" file. It should also work for XML.
HTH,
Randy
Copy link to clipboard
Copied
That looks very promising. I will give it a shot.
Is there somewhere in the docs that I can get a flavor for the overall
ecosystem that these extensions work in? For instance, it took me days to
find a reference that said this works like Netscape 4 and JS 1.5. Knowing
that I can make some decisions. Before that it was trial and error.
BTW this is how we are doing it now:
dw.scanSourceString(xmlText, parserCallbackObj);
When I saw this function it looked like a SAX parser to me, so we used it.
It seems to work well enough, but the DOM method might be easier to read and
maintain.
-Judd
Copy link to clipboard
Copied
Is there somewhere in the docs that I can get a flavor for the overall
ecosystem that these extensions work in? For instance, it took me days to
find a reference that said this works like Netscape 4 and JS 1.5. Knowing
that I can make some decisions. Before that it was trial and error.
You may have already found these, but here's the general Extensibility doc:
http://help.adobe.com/en_US/dreamweaver/cs/extend/index.html
And here's the API Reference:
http://help.adobe.com/en_US/dreamweaver/cs/apiref/index.html
The JavaScript engine for CS5 is SpiderMonkey (1.8).
BTW this is how we are doing it now: dw.scanSourceString(xmlText, parserCallbackObj);
When I saw this function it looked like a SAX parser to me, so we used it.
It seems to work well enough, but the DOM method might be easier to read and
maintain.
That is also a valid method. It gives you more control at the expense of having to write more code.
HTH,
Randy
Copy link to clipboard
Copied
I had seen those, but - and maybe its me - I had a tough time getting to the
the things I needed to. Maybe it was organization? Maybe it was examples, I
dunno. But its pretty tough to get details. Easy stuff is easy, medium stuff
is harder than it should be.
Speaking of that, how do you package an extension for release? I thought
that it was possible to make it something that can be distributed easily. Of
course, a google search yields nothing that looks like the right idea... Let
me know!
-Judd
Copy link to clipboard
Copied
Ok, maybe I just did not google it right... Shifting some stuff around
yielded this:
http://www.google.com/url?sa=t&source=web&cd=1&ved=0CCwQFjAA&url=http%3A%2F%2Fhelp.adobe.com%2Fen_US%2Fextensionmanager%2Fcs%2Fusing%2Fpackaging_extension.pdf&ei=bVbATb7HFIj50gHArL33BA&usg=AFQjCNHuJMzJiVv9FM1zWyp8nh475VKsxw
I am digging into it now.
-J
ps. thanks for all the help on this stuff.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now