trying to open the setup.xul that is produced in the Komodo extension template.
Fails:
var file = ko.macros.current.project.getChildByAttributeValue( 'name', 'setup.xul', 1 ).getFile( );
//file.path = fileURI.URI;
file.open('rb');
var str = file.readfile();
file.close();
alert( str ); //- verified and it has the right text.
var xmlDoc = new XML( str );
//exception[message] = xml is a reserved identifier
alert(xmlDoc);
I should have recognized it in the first place... This bone head has done a fair amount of stuff with Adobe. Not only ActionScript but also ExtendStript(not flash but, photoshop and most of the other CS3 stuff). This xml access is virtually identical... Adobe did remove the bug below from their version.
var xmlSettings = XML.settings( );
xmlSettings.ignoreComments = false;
xmlSettings.ignoreProcessingInstructions = false;
xmlSettings.ignoreWhitespace = true;
xmlSettings.prettyPrinting = false;
xmlSettings.prettyIndent = 0;
XML.setSettings(xmlSettings);
// The above is habit... I personally think that while xml should indeed be
// reasonably human readable, on the other hand any "good" editor would format
// with appropriate indenting at the push of a button... This should be a
// default STANDARD. Most editors that call themselves "xml aware" do this.
// However, there is a notable editor that is an exception. I dare not speak
// the name in the current context! Note that I said by DEFAULT. Meaning that
// the bone head end developer(me) shouldn't have to figure out how to set it
// up!!
//
// Now I must say that a really good xml editor would format both ways! This I
// have yet to find. The following should (ABSOLUTELY) be STANDARD DEFAULTS
// for editors that call themselves xml "masters".
//
// Click here: To format for the human being and then...
// Click here: So the interpreter doesn't have to read all the garbage spaces.
//
// Further, if I do any xslt I have found that making sure that ALL the xml is
// cleared of any tabs cr's or lf's (superfluous whitespace of ALL ilks) it
// makes the entire xslt experience dramatically easier. When I say ALL the xml
// this includes the xslt, and should not be overlooked! If I use schema the
// same "rule" applies. Something about if you allow "garbage in" you will have
// a hard time keeping "garbage out"! There are xslt "settings" for whitespace
// but, I assure you, if you just keep whitespace out in the first place it
// makes the whole thing much, much easier!
// http://www.dlgreene.com
// Click on "Code" at the top or bottom, left side... Then "Code Info" for more
// stuff. The xml(including xhtml) "code" you see is a xslt <ul>/<li> formatted
// list of xml that has ABSOLUTELY NO superfluous whitespace. The aspx C# is
// obviously quite different, as it gets compiled. This would be true for PHP
// or whatever languages that are compiled by the server.
//
// Again, as far as I'm concerned formatting for the human being is an
// operation much better handled by your editor!!! And, I feel putting that on
// the interpreter every single time it needs to read the data at run time is a
// joke!! And worse yet put the junk back in at run time when it's saved is,
// to me, not even close to funny.
///////////////////////////////////////////////////////////////////////////////
// The following getFile I'm not sure about. I see most of the code around here
// uses somekind of Components "thing" to to retrieve a file obj. My point is
// the following should probably be written by someone that knows what they are
// doing. I have found that if any BOM stuff is in the file it will crash on
// xmlXml = new XML( xmlContent );
var xmlFile = ko.macros.current.project.getChildByAttributeValue( 'name', 'install.rdf', 1 ).getFile( );
xmlFile.open( 'r' );
var xmlContent = xmlFile.readfile( );
xmlFile.close( );
// I got the following here: http://developer.mozilla.org/en/E4X
// This should probably be written in such a way as to get the encoding=""
// statement out of it, if it exists, so that it can be written back in
// properly when saved to file. This way other "real" xml apps have the
// "proper" header.
xmlContent = xmlContent.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, ""); // bug 336551
var xmlXml = new XML( xmlContent );
// This obviously needs to "query" details first but, within the current
// context is good enough... If you don't have the namespaces named in the
// same manner this will fail!!!
var nsDef = xmlXml.namespace( );
var nsEm = xmlXml.namespace( 'em' );
alert( xmlXml.toXMLString( ) );
alert( xmlXml.nsDef::Description.nsEm::id );
You can use E4X
var str = a.toString();
alert(a['first-child'].@attr == "value");
To load a file
var file = Components.classes["@activestate.com/koFileEx;1"]
.createInstance(Components.interfaces.koIFileEx)
file.path = "/tmp/test.xml";
file.open('rb');
var str = file.readfile();
var xmlDoc = new XML(str);
file.close();
alert(xmlDoc.goal)
// file /tmp/test.xml contains <main><goal>hello</goal></main> var file = Components.classes["@activestate.com/koFileEx;1"] .createInstance(Components.interfaces.koIFileEx) file.path = "/tmp/test.xml"; file.open('rb'); var str = file.readfile(); var xmlDoc = new XML(str); file.close(); alert(xmlDoc.goal)Save is very similar and easy using the koIFileEx interface
You can also use XMLSerializer and other DOM functions
--
dafi
Enhance KomodoEdit with MoreKomodo
I meant in Komoto.
trying to open the setup.xul that is produced in the Komodo extension template.
Fails:
var file = ko.macros.current.project.getChildByAttributeValue( 'name', 'setup.xul', 1 ).getFile( ); //file.path = fileURI.URI; file.open('rb'); var str = file.readfile(); file.close(); alert( str ); //- verified and it has the right text. var xmlDoc = new XML( str ); //exception[message] = xml is a reserved identifier alert(xmlDoc);I should have recognized it in the first place... This bone head has done a fair amount of stuff with Adobe. Not only ActionScript but also ExtendStript(not flash but, photoshop and most of the other CS3 stuff). This xml access is virtually identical... Adobe did remove the bug below from their version.
This works but I don't know if it's:
ContentType='application/vnd.mozilla.xul+xml'
var req = new XMLHttpRequest( ); req.open("GET", ko.macros.current.project.getChildByAttributeValue( 'name', 'setup.xul', 1 ).getFile( ).URI, false ); req.send( null ); var dom = req.responseXML; alert( dom.childNodes.length );