Discussion of the xtools Toolkit

Moderators:xbytor, DavideBarranca, Paul MR

Mike Hale

Post by Mike Hale » Sun Apr 11, 2010 1:42 pm

This may not be the best way, but it makes sense to me to edit the xml as a whole. So I would not break out the global child.

Note I don't know any thing about PE6 actions so I may have edited the wrong attributes, but the concept is valid.

Code: Select all// @include '/C/Program Files/Adobe/xtools/xlib/stdlib.js'
var pXMLFile = new File('~/Desktop/PSE6.xml');
var pXML = Stdlib.readXMLFile(pXMLFile);
var ns = new Namespace ("");
pXML.ns::global.ns::name.@value = 'newActionName';
pXML.ns::global.ns::typecategory.@value = 'newActionCategory';
Stdlib.writeXMLFile('~/Desktop/test.xml', pXML);// written to a different file for testing
var myXML = Stdlib.readXMLFile('~/Desktop/test.xml');
alert( myXML.ns::global.ns::name.@value );



Post by xbytor » Mon Apr 12, 2010 12:51 am

Mike Hale wrote:My guess is X did not intend that function to parse xml with attributes. I imagine that he has other scripts for that purpose. This function looks to me like a helper function to convert simple xml to script parameter objects similar to the one in Adobe's Image Procssor.jsx.

That sounds about right. Those pair of functions were for converting JS objects to XML and back _only_ and the usage was for complex preference files where ini files wouldn't be feasible. XML attributes are used only for metadata, specifically the underlying data types.

I know that he is really busy with a project he is working on, so in the meantime here is my fix to that function until he has time to respond.

Thanks. Dealing with xml namespaces in JS is a major bit of pain and were a bit out of scope for these functions.

I'll fold your changes into the release later this week.


Mike Hale


Post by Mike Hale » Mon Apr 12, 2010 1:24 am

xbytor wrote:I'll fold your changes into the release later this week.

I think that my fix needs work. If the element has both text and attributes, my fix will only convert the attributes as I replaced the obj. It work for the xml posted but I think it would fail in a lot of cases.



Post by myranalis » Mon Apr 12, 2010 1:25 am

I am getting an 'Expected ;' error when I run the above snippet in ESTK? It highlights the first :: operator. It doesn't seem to matter if the target is the ESTK or CS3...

Code: Select allpXML.ns::global.ns::name.@value = 'newActionName';

Mike Hale


Post by Mike Hale » Mon Apr 12, 2010 1:56 am

It seems that CS3 is the problem. I have been running in CS4. For some reason CS3 doesn't like the ns::element access and I don't know what syntax it would accept when a namespace is required.

The CS4 guide says that if you use the global function setDefaultXMLNamespace() to set the default namespace you can then use the simple accessors( xml.element ). But that didn't work for me in CS3 with passing either a string or a namespace object to simple setDefaultXMLNamespace.



Post by xbytor » Mon Apr 12, 2010 2:05 am

For this particular case, since there is only the one global namespace, just remove it.

Code: Select allvar str = Stdlib.readfromFile(file);
str.replace('xmlns=""', '');

var myXML = new XML(str);

This avoids all of the namespace nonsense. I'm currently using this technique in a project I'm involved with. It saved my sanity


Post Reply