NsXML plug-in (by rsegal): Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
mNo edit summary
 
Line 49: Line 49:
==== Description ====
==== Description ====


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.
Start an element in the document, it'll insert something like "<Start>" but not the corresponding "</Start>" which of course is what endElem is for.


==== Example ====
==== Example ====

Latest revision as of 05:21, 23 October 2009

Author: rsegal (talk, contrib)


Links

Zip.gif nsxml.zip (52KB)

The plugin is 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.

Forum thread

Description

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.

DLL Functions

nsXML::init

Description

Intializes a bunch of MSXML parser instance stuff.

Example

nsXML::init

nsXML::startDocument

Description

Starts a document in memory.

Example

nsXML::startDocument

nsXML::endDocument

Description

Ends a document in memory.

Example

nsXML::endDocument

nsXML::startElem

Description

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

Example

None at this moment.

nsXML::endElem

Description

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

Example

None at this moment.

nsXML::elemVal

Description

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

Example

None at this moment.

nsXML::insertElemVal

Description

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

Example

nsXML::insertElemVal "Hello" "123"

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

nsXML::write

Description

Writes the constrcuted XML doc out to the file you specify.

Example

nsXML::write "c:\temp.xml"

nsXML::initCOM

Description

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

Example

nsXML::initCOM

nsXML::uninitCOM

Description

Is only necessary if you don't use COM elsewhere in other plugins. Calls CoUninitialize.

Example

nsXML::uninitCOM

Example Snippet

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

TODO

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