Archive: nsXML - an MSXML NSIS XML plugin


nsXML - an MSXML NSIS XML plugin
Been working on an XML writing plugin recently and have come up with the following API...

initCOM
init
startElem
endElem
startDocument
endDocument
insertElemVal
elemVal
write
uninitCOM

I'm using MSXML and SAX for the writer so this should allow for some pretty strict error checking when required plus it's probably the XML parser I know best. Note that it only does writing right now, I'm playing around with some stuff for how parsing might work. The API is pretty much a wrapper for an MSXML SAX writer instance so if you are familiar with that then you should have no troubles. I am still open for suggestions/request so if you have some please let me know this thing is far from done. You need MSXML 3 so make sure you have that. I'm not sure if you need a specific revision of the MSXML3.dll I'll see if I can find out.

init - Intializes a bunch of MSXML parser instance
stuff
startDocument - Starts a document in memory
endDocument - Ends a document in memory

startElem - Start an element in the document, it'll insert something like "<Start>" but not the cooresponding "</Start>" which of course is what endElem is for

endElem - As I mentioned inserts the end element tag "</Start>" for example

elemVal - Inserts a value for the current element. Should be preceeded by a call to startElem and proceeded by a call to endElem

insertElemVal - Combines calls to startElement, endElement and characters to write an element into the XML document. In the example above

nsXML::insertElemVal "Hello" "123"

would insert <Hello>123</Hello> into the XML document

write - Writes the constrcuted XML doc out to the file you specify

initCOM & uninitCOM - Are only necessary if you don't use COM elsewhere in other plugins. Call CoInitialize and CoUninitialize respectively.

And here's an example script snippet which you should just be able to try out


nsXML::initCOM
nsXML::init
nsXML::startDocument
nsXML::insertElemVal "Hello" "123"
nsXML::insertElemVal "Hel2lo" "1233333"
nsXML::endDocument
nsXML::write "c:\temp.xml"
nsXML::uninitCOM


The plugins attached for you to try out although quite buggy at this point. I'm getting a crash on shutdown of any installers I make with the plugin. I'm looking into it.

Other features I plan to add...
-Search and replace on a specific element or value
-Unicode support (not sure if this is possible with language tables or not but it would be really cool if you could do it)
-support for DOM parser/writer

Cool... going to try it.... although mine was a crap :(


I remember your post on your plugin Joelito, let me know if you want to help out on this.


Hello

@Regal : Cool :up:
@Joelito: Courage . I think that 2 plugins is better thant one. I plugin for xml is a hard work. :up:

Best regards


Thanks kike :)

The thing is that I was trying to do my own parser... I can do it by using, like Regal, wrapping other parser...


If 2 is better than 1, then surely 2.5 is better than 2.

Bellow there is a link to a little XML plug-in, based on expat and scew, that I started working on and never finished. I doesn't require any external components but MSVCRT.dll. It's also, surprisingly, called nsXML. I tried to avoid having the script save handles to XML elements everywhere, so I went with something similar to XPath, but with writing ability too.

http://www.stashbox.org/uploads/1111511534/nsXML.zip


*blip* We got a code 404 situation here. Assistance required. *blip*
Looks like that link is dead. I came here for your nsXML plugin which supposedly was going to explain how to use the ExecuteCodeSegment, but no luck.


I don't know why stashbox.org isn't responding. I hope it'll get back online soon. For now, I have attached the plug-in without expat and scew.


Excellent!!!
I'l have a look at the code soon, maybe I will find out some more ways to exploit the ExecuteCodeSegment trick.


You can also check my small (11K) nsisXML plugin based on MSXML
at http://omarcoux.free.fr/nsisXML


I think Wizou's plug-in is more complete as it supports XPath. XPath is so much easier to work with than opening a child, descending checking tag attribute and repeating until what you want is found. Good for general enumeration, but this is not usually what you want. You will most likely update some configuration data when handling XML files in NSIS. Kichik and Wizou should team up and make one single XML plug-in for NSIS that does it's job.