npXmls plugin

About this plugin

This plugin allow you to scan any XML string or file (even HTML) taking the control of all possible XML parts. Events are fired when the scanner found DTD attributes, CData content, elements content, XML comments, DTD definitions (even externals), start, end and empty tags, notations, proccessing instructions, etc.

You can scan a separatelly XML string or scan a complete file. And you have complete information about the scan progress. The plugin include three samples that show how to scan an XML Books colletion, another that scan an RSS feed, and finally another that take the links data from an HTML file.

Thirparty

This plugin are imposible without the aid of this people:

Thanks a lot!

Plugin actions index

npXmlsCreate

This action creates a new instance of an Xmls object. The result variable store the ID of the new Xmls object. You can use this ID with other plugin actions.

↑↑

npXmlsDestroy

This action destruct a previously created Xmls object instance. The result variable store "True" if every is OK, or "False" if not, for example, because no instance is found with the provided ID. This action The [LastError] variable contain information about the error.

↑↑

npXmlsDestroyAll

This action destruct all previously created Xmls object instances.

↑↑

npXmlStrScan

This action scan the specified XML string, for example, the content of an XML file stored in a string variable. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

If you set Normalize to "True" (or "Checked"), the following normalization on element text content will take place:

Whitespace, as according to the XML 1.0 specification, is one of the following characters:

↑↑

npXmlFileScan

This action scan the an XML file based in the specified file path. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

See the npXmlStrScan action for details about the Normalize action param.

↑↑

npXmlAbortScan

This action allow you to abort (stop) a currently running XML scanner task. See npOnXmlAbort. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlAbort

Set a subroutine to be execute when a XML scanner task is aborted. See npXmlAbortScan. The instance ID variable contain the ID of the Xmls object that fire the event. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlAttList

Set a subroutine to be executed when the XML scanner found a !ATTLIST definition in a Document Type Declaration. The instance ID variable contain the ID of the Xmls object that fire the event. The Element variable contain an Array with two items, zero indexed, like this:

The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlCData

Set a subroutine to be executed when the XML scanner found a CDATA section. The instance ID variable contain the ID of the Xmls object that fire the event. The Content variable contain the CData section text. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlComment

Set a subroutine to be executed when the XML scanner found a comment. The instance ID variable contain the ID of the Xmls object that fire the event. The Comment variable contain the XML comment. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlContent

Set a subroutine to be executed when the XML scanner found a element text content. The instance ID variable contain the ID of the Xmls object that fire the event. The Content variable contain the element text content. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlDtdError

Set a subroutine to be executed when the XML scanner found a error in a DTD. The instance ID variable contain the ID of the Xmls object that fire the event. The Error position variable contain the position of the error in the DTD. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlDtdRead

Set a subroutine to be executed when the XML scanner read a Document Type Declaration. The instance ID variable contain the ID of the Xmls object that fire the event. The Root name variable contain the name of the DTD root name. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlElement

Set a subroutine to be executed when the XML scanner found a !ELEMENT definition in the DTD. The instance ID variable contain the ID of the Xmls object that fire the event. The Element variable contain an Array with three items, zero indexed, like this:

The element type can be one of the following values: Empty, Any, Childs only, Mixed.

The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlEmptyTag

Set a subroutine to be executed when the XML scanner found a empty element tag. The instance ID variable contain the ID of the Xmls object that fire the event. The Tag name variable contain the found tag name. The Attributes variable contain the full list of the tag attributes. The Attributes count variable contain the total number of attributes on the tag. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

Note that the Attributes variable is an "Array of an Array". In fact Attributes contain the same number of items that attributes found in the tag. And every Attribute Array item contain another "Array" with the information about every tag attribute. This can be appear complex at the first time, but is really easy to understand: you can see the plugin samples and take a look at their NeoBook code.

So every item in the Attributes variable is a zero indexed "Array" with four elements:

The attribute type can be one of the following values: Unknown, CDATA, ID, IDREF, IDREFS, ENTITY, ENTITIES, NMTOKEN, NMTOKENS, Notation, Enumeration.

The attribute type value can be one of the following values: Normal, Implied, Fixed, Default.

Take the idea of the "Arrays of Arrays", finally here is a sample code:

.You want the value of the first tag attribute found
If "[AttributesCount]" ">" "0"
  SetVar "[AttrValue]" "[0Attributes1]"
EndIf
.Save in the TagAttributes all tag attributes found
Loop "0" "[AttributesCount]" "[i]"
  Loop "0" "3" "[j]"
    SetVar "[[i]TagAttributes[j]]" "[[i]Attributes[j]]"
  EndLoop
EndLoop

If you like, is possible to name the Attributes variable something like this: [_Attributes_]", so, the last code look like this:

.Save in the TagAttributes all tag attributes found
Loop "0" "[AttributesCount]" "[i]"
  Loop "0" "3" "[j]"
    SetVar "[[i]TagAttributes[j]]" "[[i]_Attributes_[j]]"
  EndLoop
EndLoop

Maybe you considerer this increase the readabilty of the code. You choose!

↑↑

npOnXmlEndTag

Set a subroutine to be executed when the XML scanner found a element end tag. The instance ID variable contain the ID of the Xmls object that fire the event. The Tag name variable contain the found tag name. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlEntity

Set a subroutine to be executed when the XML scanner found a !ENTITY definition in the DTD. The Entity variable contain this zero indexed Array with three items:

The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlLoadExternal

Set a subroutine to be executed when the XML scanner found a external entity reference or a external DTD reference. With this action you can load (to be scaned) any external entity or external DTD reference. The system ID variable contain the system identifier of the external entity. This is always given and is the URI of the file to load.

The instance ID variable contain the ID of the Xmls object that fire the event. The Public ID variable contain the public identifier of the external entity. This is optional. And the Notation variable contain the identifier of the external entity. Only applicable for General Unparsed External Entities.

In any case is your choice to load or not the external reference. If do, put the XML content to the XML Result variable, so the scanner begin to scan the XML content of the external reference. If you not put anything to the XML Result variable, simply the external reference is not scan.

The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlPI

Set a subroutine to be executed when the XML scanner found a Processing Instruction (PI). The instance ID variable contain the ID of the Xmls object that fire the event. The Target variable contain the target name of the PI. The Content variable contain the rest of the Procesing Instruction. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlStartTag

Set a subroutine to be executed when the XML scanner found a element start tag. The instance ID variable contain the ID of the Xmls object that fire the event. I want to refer you to the npOnXmlEmptyTag action help, because the same things apply in this case. Thank you!

↑↑

npOnXmlWork

Set a subroutine to be executed while the XML parser is working. The instance ID variable contain the ID of the Xmls object that fire the event. The Processed bytes variable contain the currently number of processed bytes. In conjuction npOnXmlWorkBegin and npOnXmlWorkEnd, you can use this in order to show progress information about the scanner task, for example. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlWorkBegin

Set a subroutine to be executed when the XML parser work begin. The instance ID variable contain the ID of the Xmls object that fire the event. In conjuction npOnXmlWork and npOnXmlWorkEnd, you can use this in order to show progress information about the scanner task, for example. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlWorkEnd

Set a subroutine to be executed when the XML parser work end. The instance ID variable contain the ID of the Xmls object that fire the event. In conjuction npOnXmlWork and npOnXmlWorkBegin, you can use this in order to show progress information about the scanner task, for example. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

npOnXmlProlog

Set a subroutine to be executed when the XML scanner found a XML declaration or a text declaration. The instance ID variable contain the ID of the Xmls object that fire the event. The XML version variable contain the XML version of the scanned string or file. The Xml encoding variable the same thing about the character encoding. And the Standalone variable contain "True" when XML standalon attribute is set to true, or "False" when not. The result variable stored "True" if everything is OK, or "False" when not. The [LastError] variable contain information about the error.

↑↑

Action errors subroutine

All the NeoPlugins deal with errors in the same way that NeoBook does: when the plugin found an action error the [LastError] variable store information about the error, so you can take care about this variable when execute an action.

But all the NeoPlugins also incorporate an advanced way to deal with possible action errors. You can define a subroutine named OnNeoPluginActionError in order to be executed when some action error are found and you can use this variables inside:

Note that this error handling subroutine are shared for all the NeoPlugins, so you no need to specify a subroutine for every plugin you use in your publication because the same subroutine are recognized and automagically used by every NeoPlugin. Below you can view a sample of this subroutine code:

:OnNeoPluginActionError
  AlertBox "NeoPlugin Error" "Error [LastError] in plugin: [PluginName]"
Return

Also note that the use of this NeoPlugins error handling subroutine is completelly optional. You can continue using the [LastError] variable as usual and even use the both methods at the same time.

↑↑