XML Spy Document Editor Browser Plug-in

xml spy
XML Spy Document Editor Browser Plug-in

The Document Editor Browser Plug-In is a unique solution that allows live XML content editing from any desktop in your enterprise, which dramatically eases deployment and reduces total cost of ownership (TCO).

This is the first browser-based XML editing solution in the entire industry, and it is based upon open standards, such as XML Schema and XSLT! It is also fully Unicode compatible!

The purpose of the XMLSpy Browser Plug-In is to make it possible to:
· edit an XSLT transformed XML document within an HTML page

This makes it possible for users to edit XML files in a WYSIWYG fashion without seeing the underlying raw XML code. There is also no need for extra software deployment, if you embed the plug-in into Internet Explorer. The first time a user visits your HTML page, the ActiveX control is installed and automatically activated.

The XMLSpy Browser Plugin is an ActiveX control where the COM interface is defined by the XMLSpyDocumentEditor object.

The complete object model of the Browser Plugin consists of the following parts:

XMLData
XMLSpyDocumentEditor
XMLSpyXMLLoadSave

Top Next

© 2002 Altova


The OBJECT tag

The OBJECT tag

To use the Browser plug-in with an HTML page, the following HTML "OBJECT" tag must be used.

<OBJECT id=XMLSpyPlugin style="WIDTH:500px; HEIGHT:500px"
    codeBase="http://plugin.xmlspy.com/cabfiles/XMLSpyPlugin.CAB#Version=2,0,0,0"
    classid=clsid:46987108-BA64-4fd1-A947-1BF7DA938FC0>
    <PARAM NAME="XMLDataURL" VALUE="http://plugin.xmlspy.com/Altova.xml">
    <PARAM NAME="SPSDataURL" VALUE="http://plugin.xmlspy.com/Altova.sps">
    <PARAM NAME="SchemaDataURL" VALUE="http://plugin.xmlspy.com/Altova.xsd">
    <PARAM NAME="LicKey" VALUE="XBA760-9HF1TT-Aq9FXB-0HstC2">
    <PARAM NAME="LicCompany" VALUE="Test">
    <PARAM NAME="LicUser" VALUE="Test">
</OBJECT>

Please note that the values for the various parameters and attributes of the OBJECT tag, must be replaced with valid data for this sample to work (i.e. a valid XML data file name and path for the "XMLDataURL" parameter).

XMLDataURL: This is the location of the XML data file that is loaded into the plugin. This will also be the XML data file that is edited. The location of the file must be an absolute URL.

SPSDataURL: This is the location of the XMLSpy XSLT Designer generated SPS file. The location of the file must be an absolute URL.

SchemaDataURL: This is the location of the Schema file used to validate the XML file. The location of the file must be an absolute URL.

LicKey: This is the license key used to validate the use of the XMLSpy Browser Plugin. The example license key in the example above, cannot be used for this purpose. Please see the License information for more information.

LicCompany: This is the company name of the license key specified in the LicKey PARAM definition.

LicUser: This is the user name of the license key specified in the LicKey PARAM definition.

LicServer: This is the name of the server if you put your license information in a separate key.

LicFile: This is the file name where the key is stored.

Please see "License information" for more information about the LicServer and LicFile parameters.

Previous Top Next


A simple HTML

A simple HTML

The HTML code below generates a page containing buttons which call simple functions using the XMLSpy Browser Plug-in. You can use this code as a template to build more complex solutions using the control.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Minimal XMLSpyDocEditPlugIn page</title>

<SCRIPT ID=clientEventHandlers LANGUAGE=vbscript>
Sub BtnOnSave
   objPlugIn.XMLDataSaveUrl = "http://plugin.xmlspy.com/SaveFile.xml"
   objPlugIn.Save
End Sub

Sub BtnOnClick
   objPlugIn.SchemaLoadObject.URL = "http://plugin.xmlspy.com/OrgChart.xml"
   objPlugIn.XMLDataLoadObject.URL = "http://plugin.xmlspy.com/OrgChart.xml"
   objPlugIn.DesignDataLoadObject.URL = "http://plugin.xmlspy.com/OrgChart.sps"
   objPlugIn.StartEditing
End Sub

Sub OnClickFind
   objPlugIn.FindDialog
End Sub

Sub OnClickReplace
   objPlugIn.ReplaceDialog
End Sub

Sub BtnOnTestProp
   If objPlugIn.IsRowInsertEnabled Then
      msgbox "true"
   Else
      msgbox "false"
   End If
End Sub

</SCRIPT>
</head>

<body>
<OBJECT id=objPlugIn
   odeBase="http://plugin.xmlspy.com/XMLSpyPluginCabinet.cab#Version=2,0,0,0"
   lassid=clsid:46987108-BA64-4fd1-A947-1BF7DA938FC0 width="600" height="500">
   <PARAM NAME="LicServer" VALUE="http://plugin.xmlspy.com">
      <PARAM NAME="LicFile" VALUE="/key.lic">
</OBJECT>

<p><input type="button" value="Start editing" name="B3" onclick="BtnOnClick"></p>
<p><input type="button" value="Find" name="B4" onclick="OnClickFind"></p>
<p><input type="button" value="Replace" name="B5" onclick="OnClickReplace"></p>
<p><input type="button" value="Save" name="B6" onclick="BtnOnSave"></p>
<p><input type="button" value="Test property" name="B7" onclick="BtnOnTestProp"></p>
</body>
</html>

Please note that the values for the various parameters and attributes of the OBJECT tag, must be replaced with valid data for this sample to work.


Row operations

Row operations

Repeatable elements can be created within an XML Document. This is made possible by the specific schema file to which the XML file is assigned. The WYSIWIG environment allows you to manipulate rows and their data, individually.

An XML row may be implemented by an HTML table, but this need not always be the case. The XSLT Designer *.SPS file defines the HTML page layout. While editing XML data, an external script performs the row operations (on each row individually).

If an external script is to perform row operations then two steps must occur:
· The first step checks whether the cursor is currently in a row using a property. E.g. IsRowInsertEnabled, which returns a TRUE or FALSE value.
· If the return value is TRUE then the row method can be called. E.g. RowAppend, which has no parameters and returns no value.

The following is a list of properties and methods available that perform table operations. Each of the properties return a BOOL and each of the methods have no parameters.

IsRowInsertEnabled, RowInsert: Row insertion operation.
IsRowAppendEnabled, RowAppend: Append row operation.
IsRowDeleteEnabled, RowDelete: Delete row operation.
IsRowMoveUpEnabled, RowMoveUp: Move the XML data up one row location.
IsRowMoveDownEnabled, RowMoveDown: Move the XML data down one row location.
IsRowDuplicateEnabled, RowDuplicate: Duplicate the currently selected XML row.


Editing operations

Editing operations

When XML data is displayed as HTML data, it is possible to manipulate individual elements using standard editing operations cut, copy and paste.

Not all XML data elements can be edited however, and it is therefore necessary first to test if editing is possible. This is achieved in the same way as row operations, starting with a property to test editing capabilities and then calling the method to perform the editing operation.

The only method that does not have a test is the method EditSelectAll, which automatically selects all elements displayed in the document. The following is a list of properties and methods available that perform editing operations. Each of the properties returns a BOOL and each of the methods have no parameters.

IsEditUndoEnabled, EditUndo | Undo an editing operation
IsEditRedoEnabled, EditRedo: | Redo an editing operation
IsEditCopyEnabled, EditCopy | Copy the selected text to the Windows clipboard
IsEditCutEnabled, EditCut | Cut the selected text to the Windows clipboard
IsEditPasteEnabled, EditPaste | Paste the Windows clipboard text to the current cursor position
IsEditClearEnabled, EditClear | Clear the selected text from the XML document


Find and replace

Find and replace

When navigating through a complex document it is often difficult to find specific sections of text.

The FindDialog() method, opens a Find dialog box. The user can then search for a specific element. The FindNext() method allows the next instance of the same item to be found. The FindNext method can be tested using the BOOL property IsFindNextEnabled, to see if there is a further occurence.

A variation of the FindDialog method is the ReplaceDialog() method. This operation finds a specific item, and is used to replace the item with a specific value entered by the user in the Replace dialog box. If the FindNext method is then called, the next item is found and replaced.


Shortcut keys

Shortcut keys

The following shortcut keys are valid if the Document Editor browser plugin has the input focus:

CTRL + P Print document
CTRL + Z Undo
CTRL + Y Redo
CTRL + X Cut
CTRL + C Copy
CTRL + V Paste
CTRL + A Select all
CTRL + F open Find dialog box
CTRL + H open Find-Replace dialog box


License information

License information

There are two ways you can supply the license information for the Document Editor Plug-in.

First, use the LicUser, LicCompany and LicKey parameters of the OBJECT tag, or the properties of the plugin interface with the same names. This method is easy to set up, you just type your license data into the HTML code of your page. If you use this method, your keycode will be visible to anyone who is able to view your HTML pages.

Alternatively, store the license key in a file located on a server.

To place the license on the server:

1. Request a key from us (Altova.com) with the name of the server (e.g. "http://www.nanonull.com") where you want to put the key (and propably the plugin).

The new key will be bound to that server.

2. Create a license file (e.g. naming it key.lic) containing the license code in plain text as the only content at the specific location.
Example: "http://www.nanonull.com/key.lic"

3. In your HTML code use the following parameters in the OBJECT tag:
<PARAM NAME="LicServer" VALUE="http://www.nanonull.com">
<PARAM NAME="LicFile" VALUE="/key.lic">

The license information is now bound to your server and also located there.

It is not possible to take the key from the file and set the properties (LicKey, LicCompany, LicUser) of the control with this information. This will be forbidden by the control itself. You can also protect the file storing the license information with a password, if you set up your server accordingly.


Using XMLData

Using XMLData

XMLData gives you access to the elements of the currently displayed XML file. It enables you to perform all necessary modifications to the elements of the XML structure. The main functionality of XMLData is:

1. Access to the names and values of all kinds of elements (e.g. elements, attributes)

2. Creation of new elements of all kinds.

3. Insertion and appending of new elements.

4. Erasing of existing child elements.

Structure of XMLData

Before you can use the XMLData interface, you have to know how an existing XML file is mapped into a XMLData structure. One major thing you must be aware of is, that XMLData has no seperate branch of objects for attributes.

The attributes of an element are also children of the element. The "XMLData.Kind" property, gives you the opportunity to distinguish between the different types of children of an element.

Example:

This XML code,

   <ParentElement>
      <FirstChild attr1="Red" attr2="Black">
         This is the value of FirstChild
      </FirstChild>
      <SecondChild>
         <!--Your Comment-->
         </DeepChild>
      </SecondChild>
      This is Text
   </ParentElement>

is mapped to the following XMLData object structure:

The parent of all XML elements inside of a file is the property "XMLSpyDocumentEditor.XMLRoot". Use this XMLData object to get references to all other XML elements in the structure.

Name and value of elements

To get and to modify the name and value of all types of XML elements use the "XMLData.Name" and "XMLData.TextValue" properties. It is possible that several kinds of XMLData objects and empty elements do not have a text value associated.

Creation and insertion of new XMLData objects

The creation of a new XML language entity requires the following steps:

1. Create the new XMLData object:
Use the "XMLSpyDocumentEditor.CreateChild" method to create a new XMLData object. Set name and value after you have inserted the new XML entity (see point 3).

2. Find the correct location for the new XMLData object:
To insert a new XMLData object you have to get a reference to the parent first. If the new child is to become the last child of the parent, use the "XMLData.AppendChild" method to insert the XMLData object.
If the new child should be located elsewhere in the sequence of child objects, use the "XMLData.GetFirstChild" and "XMLData.GetNextChild" to move the iterator to the child before which the new child should be inserted.

3. Insert the new child with "XMLData.InsertChild"
The new child will be inserted immediately before the current child.

The following example adds a third child between <FirstChild> and the <SecondChild> element:

   Dim objParent
   Dim objChild
   Dim objNewChild

   Set objNewChild = objPlugIn.CreateChild(spyXMLDataElement)

   'objParent is set to <ParentElement>
   'GetFirstChild(-1) gets all children of the parent element
   'and move to <SecondChild>
   Set objChild = objParent.GetFirstChild(-1)
   Set objChild = objParent.GetNextChild

   objParent.InsertChild objNewChild
   objNewChild.Name = "OneAndAHalf"
   Set objNewChild = Nothing

Copying of existing XMLData objects

If you want to insert existing XMLData objects at a different place in the same file you can't use the XMLData.InsertChild and XMLData.AppendChild methods. These methods only work for new XMLData objects.

Instead of using InsertChild or AppendChild you have to copy the object hierarchy manually. The following function written in JavaScript is an example for recursively copying XMLData:

   // this function returns a complete copy of the XMLData object
   function GetCopy(objXMLData)
   {
      var objNew;
      objNew = objPlugIn.CreateChild(objXMLData.Kind);

      objNew.Name = objXMLData.Name;
      objNew.TextValue = objXMLData.TextValue;

      if(objXMLData.HasChildren)   {
         var objChild;
         objChild = objXMLData.GetFirstChild(-1);

         while(objChild)   {
            try {
               objNew.AppendChild(GetCopy(objChild));
               objChild = objXMLData.GetNextChild();
            }
            catch(e) {
               objChild = null;
            }
         }
      }

      return objNew;
   }

Erasing of XMLData objects

XMLData provides two methods for the deletion of child objects, "XMLData.EraseAllChildren" and "XMLData.EraseCurrentChild".

To erase XMLData objects you need access to the parent of the elements you want to remove. Use "XMLData.GetFirstChild" and "XMLData.GetNextChild" to get a reference to the parent XMLData object.

See the method descriptions of "EraseAllChildren" and "EraseCurrentChild" for examples how to erase XML elements.


DOM and XMLData

DOM and XMLData

The XMLData interface gives you full access to the XML structure behind the current document with less methods than DOM and is much simpler. The XMLData interface is a minimalist approach to reading and modifying existing, or newly created XML data. You might however, want to use a DOM tree because you can access one from an external source or you just prefer the MSXML DOM implementation.

The ProcessDOMNode() and ProcessXMLDataNode() functions provided below convert any segments of an XML structure between XMLData and DOM.

To use the ProcessDOMNode() function:
· pass the root element of the DOM segment you want to convert in objNode and
· pass the plugin object with the CreateChild() method in objCreator

To use the ProcessXMLDataNode() function:
· pass the root element of the XMLData segment in objXMLData and
· pass the DOMDocument object created with MSXML in xmlDoc

////////////////////////////////////////////////////////////////
// DOM to XMLData conversion

function ProcessDOMNode(objNode,objCreator)
{
   var objRoot;
   objRoot = CreateXMLDataFromDOMNode(objNode,objCreator);

   if(objRoot)   {
      if((objNode.nodeValue != null) && (objNode.nodeValue.length > 0))
         objRoot.TextValue = objNode.nodeValue;

      // add attributes
      if(objNode.attributes) {
         var Attribute;
         var oNodeList = objNode.attributes;

         for(var i = 0;i < oNodeList.length; i++) {
            Attribute = oNodeList.item(i);

            var newNode;
            newNode = ProcessDOMNode(Attribute,objCreator);

            objRoot.AppendChild(newNode);
         }
      }

      if(objNode.hasChildNodes)   {
         try {
            // add children
            var Item;
            oNodeList = objNode.childNodes;

            for(var i = 0;i < oNodeList.length; i++) {
                  Item = oNodeList.item(i);

               var newNode;
               newNode = ProcessDOMNode(Item,objCreator);

               objRoot.AppendChild(newNode);
            }
         }
         catch(err) {
         }
      }
   }

   return objRoot;
}

function CreateXMLDataFromDOMNode(objNode,objCreator)
{
   var bSetName = true;
   var bSetValue = true;

   var nKind = 4;

   switch(objNode.nodeType)   {
      case 2:nKind = 5;break;
      case 3:nKind = 6;bSetName = false;break;
      case 4:nKind = 7;bSetName = false;break;
      case 8:nKind = 8;bSetName = false;break;
      case 7:nKind = 9;break;
   }

   var objNew = null;
   objNew = objCreator.CreateChild(nKind);

   if(bSetName)
      objNew.Name = objNode.nodeName;

   if(bSetValue && (objNode.nodeValue != null))
      objNew.TextValue = objNode.nodeValue;

   return objNew;
}

////////////////////////////////////////////////////////////////
// XMLData to DOM conversion

function ProcessXMLDataNode(objXMLData,xmlDoc)
{
   var objRoot;
   objRoot = CreateDOMNodeFromXMLData(objXMLData,xmlDoc);

   if(objRoot)   {
      if(IsTextNodeEnabled(objRoot) && (objXMLData.TextValue.length > 0))
         objRoot.appendChild(xmlDoc.createTextNode(objXMLData.TextValue));

      if(objXMLData.HasChildren)   {
         try {
            var objChild;
            objChild = objXMLData.GetFirstChild(-1);

            while(true)   {
               if(objChild)   {
                  var newNode;
                  newNode = ProcessXMLDataNode(objChild,xmlDoc);

                  if(newNode.nodeType == 2)   {
                     // child node is an attribute
                     objRoot.attributes.setNamedItem(newNode);
                  }
                  else
                     objRoot.appendChild(newNode);
               }

               objChild = objXMLData.GetNextChild();
            }
         }
         catch(err) {
         }
      }
   }

   return objRoot;
}

function CreateDOMNodeFromXMLData(objXMLData,xmlDoc)
{
   switch(objXMLData.Kind)   {
      case 4:return xmlDoc.createElement(objXMLData.Name);
      case 5:return xmlDoc.createAttribute(objXMLData.Name);
      case 6:return xmlDoc.createTextNode(objXMLData.TextValue);
      case 7:return xmlDoc.createCDATASection(objXMLData.TextValue);
      case 8:return xmlDoc.createComment(objXMLData.TextValue);
      case 9:return xmlDoc.createProcessingInstruction(objXMLData.Name,objXMLData.TextValue);
   }

   return xmlDoc.createElement(objXMLData.Name);
}

function IsTextNodeEnabled(objNode)
{
   switch(objNode.nodeType) {
      case 1:
      case 2:
      case 5:
      case 6:
      case 11:return true;
   }

   return false;
}


XMLData

See also

Methods
InsertChild
AppendChild

EraseAllChildren
EraseCurrentChild

GetCurrentChild
GetFirstChild
GetNextChild

IsSameNode

Properties
Name
TextValue

HasChildren
MayHaveChildren

Kind
Parent

Description

You can use the XMLData interface to manipulate the content of the currently displayed XML. This interface is a lightweight COM counterpart of the implementation used inside the plugin and XMLSpy itself.

To create a new XMLData object use the CreateChild() method of the plugin interface.


InsertChild

XMLData.InsertChild

Declaration: InsertChild(pNewData as XMLData)

Description

InsertChild inserts the new child before the current child (see also XMLData.GetFirstChild, XMLData.GetNextChild to set the current child).


AppendChild

XMLData.AppendChild

Declaration: AppendChild(pNewData as XMLData)

Description

AppendChild appends pNewData as last child to the XMLData object. See also "Using XMLData".

Example

   Dim objCurrentParent
   Dim objNewChild

   Set objNewChild = objPlugIn.CreateChild(spyXMLDataElement)
   Set objCurrentParent = objPlugIn.XMLRoot

   objCurrentParent.AppendChild objNewChild

   Set objNewChild = Nothing


EraseAllChildren

XMLData.EraseAllChildren

Declaration: EraseAllChildren

Description

EraseAllChildren deletes all associated children of the XMLData object.

Example

The sample erases all elements of the active document.

   Dim objCurrentParent

   Set objCurrentParent = objPlugIn.XMLRoot
   objCurrentParent.EraseAllChildren


EraseCurrentChild

XMLData.EraseCurrentChild

Declaration: EraseCurrentChild

Description

EraseCurrentChild deletes the current XMLData child object. Before you call EraseCurrentChild you must initialize an internal iterator with XMLData.GetFirstChild.

Example

This JavaScript example deletes all elements with the name "EraseMe". The code shows you, that it is possible to call EraseCurrentChild and GetNextChild inside the same loop to continue stepping through the child elements.

   function DeleteXMLElements(objXMLData)
   {
      if(objXMLData == null)
         return;

      if(objXMLData.HasChildren)   {
         var objChild;
         objChild = objXMLData.GetFirstChild(-1);

         while(objChild)   {
            DeleteXMLElements(objChild);

            try   {
               if(objChild.Name == "EraseMe")
                  objXMLData.EraseCurrentChild();

               objChild = objXMLData.GetNextChild();
            }
            catch(Err)   {
               objChild = null;
            }
         }
      }
   }


GetCurrentChild

XMLData.GetCurrentChild

Declaration: GetCurrentChild as XMLData

Return Value
Returns an xml element as XMLData object.

Description

GetCurrentChild gets the current child. Before you call GetCurrentChild you must initialize an internal iterator with XMLData.GetFirstChild.


GetFirstChild

XMLData.GetFirstChild

Declaration: GetFirstChild(nKind as SPYXMLDataKind) as XMLData

Return Value
Returns an xml element as XMLData object.

Description

GetFirstChild initializes a new iterator and returns the first child. Set nKind = -1 to get an iterator for all kinds of children.

Example

See the example at XMLData.GetNextChild.


GetNextChild

XMLData.GetNextChild

Declaration: GetNextChild as XMLData

Return Value
Returns an xml element as XMLData object.

Description

GetNextChild steps to the next child of this element. Before you call GetNextChild you must initialize an internal iterator with XMLData.GetFirstChild.

Check for the last child of the element as shown in the sample below.

Example

   On Error Resume Next
   Set objParent = objPlugIn.XMLRoot

   'get elements of all kinds
   Set objCurrentChild = objParent.GetFirstChild(-1)

   Do
      'do something useful with the child

      'step to next child
      Set objCurrentChild = objParent.GetNextChild
   Loop Until (Err.Number - vbObjectError = 1503)


Name

XMLData.Name

Declaration: Name as String

Description

Used to modify and to get the name of the XMLData object.


TextValue

XMLData.TextValue

Declaration: TextValue as String

Description

Used to modify and to get the text value of this XMLData object. See also "Using XMLData".


HasChildren

XMLData.HasChildren

Declaration: HasChildren as Boolean

Description

The property is true, if the object is parent of other XMLData objects.

This property is read-only.


MayHaveChildren

XMLData.MayHaveChildren

Declaration: MayHaveChildren as Boolean

Description

Tells if it is allowed to add children to this XMLData object.

This property is read-only.


Kind

XMLData.Kind

Declaration: Kind as SPYXMLDataKind

Description

Kind of this XMLData object.

This property is read-only.


IsSameNode

XMLData.IsSameNode

Declaration: IsSameNode(pNodeToCompare as XMLData) as Boolean

Description

Returns true if pNodeToCompare references to the same node as the object itself.


Parent

XMLData.Parent

Declaration: Parent as XMLData

Return value
Parent as XMLData object.
Nothing (or NULL) if there is no parent element.

Description

Parent of this element.

This property is read-only.


XMLSpyDocumentEditor

Methods

StartEditing
LoadXML
Reset

Save
SavePOST
SaveXML

ValidateDocument

EditClear
EditCopy
EditCut
EditPaste
EditRedo
EditSelectAll
EditUndo

RowAppend
RowDelete
RowDuplicate
RowInsert
RowMoveDown
RowMoveUp

FindDialog
FindNext
ReplaceDialog

ApplyTextState
IsTextStateApplied
IsTextStateEnabled

MarkUpView

Print
PrintPreview

CreateChild

GetAllowedElements

GetNextVisible
GetPreviousVisible

SelectionMoveTabOrder
SelectionSet

attachCallBack

Properties

IsEditClearEnabled
IsEditCopyEnabled
IsEditCutEnabled
IsEditPasteEnabled
IsEditRedoEnabled
IsEditUndoEnabled

IsFindNextEnabled

IsRowAppendEnabled
IsRowDeleteEnabled
IsRowDuplicateEnabled
IsRowInsertEnabled
IsRowMoveDownEnabled
IsRowMoveUpEnabled

LicCompany
LicFile
LicKey
LicServer
LicUser

SchemaLoadObject
XMLDataLoadObject
DesignDataLoadObject

XMLDataSaveUrl

XMLRoot

CurrentSelection

event

validationBadData
validationMessage

Events

SelectionChanged

Description

XMLSpyDocumentEditor Class


ApplyTextState

XMLSpyDocumentEditor.ApplyTextState

Declaration: ApplyTextState(elementName as String)

Description

Applies or removes the text state defined by the parameter elementName. Common examples for the parameter elementName would be strong and italic.

In an XML document there are segments of data, which may contain sub-elements. For example consider the following HTML:

   <b>fragment</b>

The HTML tag <b> will cause the word fragment to be bolded. However, this only happens because the HTML parser knows that the tag <b> is bold. With XML there is much more flexibility. It is possible to define any XML tag to do anything you desire. The point is that it is possible to apply a Text state using XML. But the Text state that is applied must be part of the schema. For example in the OrgChart.xml OrgChart.sps, OrgChart.xsd example the tag <strong> is the same as bold. And to apply bold the method ApplyTextState() is called. But like the row and edit operations it is necessary to test if it is possible to apply the text state.

See also IsTextStateEnabled and IsTextStateApplied.


CreateChild

XMLSpyDocumentEditor.CreateChild

Declaration: CreateChild(nKind as SPYXMLDataKind) as XMLData

Return Value
New XML node

Description

The CreateChild method is used to create new nodes which you can insert into the XML structure of the current document using the XMLData interface.

The values for the nKind parameter are as follows:

spyXMLDataXMLDocStruct = 0
spyXMLDataXMLEntityDocStruct = 1
spyXMLDataDTDDocStruct = 2
spyXMLDataXML = 3
spyXMLDataElement = 4
spyXMLDataAttr = 5
spyXMLDataText = 6
spyXMLDataCData = 7
spyXMLDataComment = 8
spyXMLDataPI = 9
spyXMLDataDefDoctype = 10
spyXMLDataDefExternalID = 11
spyXMLDataDefElement = 12
spyXMLDataDefAttlist = 13
spyXMLDataDefEntity = 14
spyXMLDataDefNotation = 15
spyXMLDataKindsCount = 16

See also XMLData.AppendChild and XMLData.InsertChild


EditClear

XMLSpyDocumentEditor.EditClear

Declaration: EditClear

Description

Clears the current selection.


EditCopy

XMLSpyDocumentEditor.EditCopy

Declaration: EditCopy

Description

Copies the current selection to the clipboard.


EditCut

XMLSpyDocumentEditor.EditCut

Declaration: EditCut

Description

Cuts the current selection from the document and copies it to the clipboard.


EditPaste

XMLSpyDocumentEditor.EditPaste

Declaration: EditPaste

Description

Pastes the content from the clipboard into the document.


EditRedo

XMLSpyDocumentEditor.EditRedo

Declaration: EditRedo

Description

Redo the last undo step.


EditSelectAll

XMLSpyDocumentEditor.EditSelectAll

Declaration: EditSelectAll

Description

The method selects the complete document.


EditUndo

XMLSpyDocumentEditor.EditUndo

Declaration: EditUndo

Description

Undo the last action.


FindDialog

XMLSpyDocumentEditor.FindDialog

Declaration: FindDialog

Description

Displays the FindDialog.

See also Find and replace.


FindNext

XMLSpyDocumentEditor.FindNext

Declaration: FindNext

Description

The method performs a find next operation.

See also Find and replace.


IsTextStateApplied

XMLSpyDocumentEditor.IsTextStateApplied

Declaration: IsTextStateApplied(elementName as String) as Boolean

Description

Checks to see if the it the text state has already been applied. Common examples for the parameter elementName would be strong and italic.


IsTextStateEnabled

XMLSpyDocumentEditor.IsTextStateEnabled

Declaration: IsTextStateEnabled(elementName as String) as Boolean

Description

Checks to see if it is possible to apply a text state. Common examples for the parameter elementName would be strong and italic.


LoadXML

XMLSpyDocumentEditor.LoadXML

Declaration: LoadXML(xmlString as String)

Description

Loads the current XML document with the XML string applied. The new content is displayed immediately.


MarkUpView

XMLSpyDocumentEditor.MarkUpView

Declaration: MarkUpView(kind as long)

Description

By default the document displayed is using HTML techniques. But sometimes it is desirable to show the editing tags. Using this method it is possible to display three different types of markup tags:

k_XMLSpyContentMarkupHide (0) hide the markup tags
k_XMLSpyContentMarkupLarge (2) show the large markup tags
k_XMLSpyContentMarkupMix (3) show the mixed markup tags.


Print

XMLSpyDocumentEditor.Print

Declaration: Print

Description

Print the current document being edited.


PrintPreview

XMLSpyDocumentEditor.PrintPreview

Declaration: PrintPreview

Description

Print preview the document being edited.


ReplaceDialog

XMLSpyDocumentEditor.ReplaceDialog

Declaration: ReplaceDialog

Description

Displays the ReplaceDialog.

See also Find and replace.


Reset

XMLSpyDocumentEditor.Reset

Declaration: Reset

Description

Reset the data being edited. Typically called before editing a new set of XML, XSL and SPS documents.

The method does not change the view and its still possible to continue working with the currently displayed document.


RowAppend

XMLSpyDocumentEditor.RowAppend

Declaration: RowAppend

Description

Appends a row at the current position.

See also Row operations.


RowDelete

XMLSpyDocumentEditor.RowDelete

Declaration: RowDelete

Description

Deletes the currently selected row(s).

See also Row operations.


RowDuplicate

XMLSpyDocumentEditor.RowDuplicate

Declaration: RowDuplicate

Description

The method duplicates the currently selected rows.

See also Row operations.


RowInsert

XMLSpyDocumentEditor.RowInsert

Declaration: RowInsert

Description

Inserts a new row immediately above the current selection.

See also Row operations.


RowMoveDown

XMLSpyDocumentEditor.RowMoveDown

Declaration: RowMoveDown

Description

Moves the current row one position down.

See also Row operations.


RowMoveUp

XMLSpyDocumentEditor.RowMoveUp

Declaration: RowMoveUp

Description

Moves the current row one position up.

See also Row operations.


Save

XMLSpyDocumentEditor.Save

Declaration: Save

Description

Saves the document to the URL specified by the property XMLDataSaveUrl.

The plugin sends an HTTP PUT request to the server to save the currently displayed XML file.


SavePOST

XMLSpyDocumentEditor.SavePOST

Declaration: SavePOST

Description

Saves the document to the URL specified by the property XMLDataSaveUrl.

The plugin sends an HTTP POST request to the server to save the currently displayed XML file.


SaveXML

XMLSpyDocumentEditor.SaveXML

Declaration: SaveXML as String

Return Value
XML structure as string

Description

Saves the current XML data to a string that is returned to the caller.


StartEditing

XMLSpyDocumentEditor.StartEditing

Declaration: StartEditing as Boolean

Return Value
True if all files were successfully loaded and displayed.

Description

Start editing the current document. It is important to set the properties of the load objects SchemaLoadObject, DesignDataLoadObject and XMLDataLoadObject first.


ValidateDocument

XMLSpyDocumentEditor.ValidateDocument

Declaration: ValidateDocument(showResults as Boolean) as Boolean

Return Value
result of validation

Description

Validates the current XML data for correctness as per the XML schema data. If the parameter showResults is FALSE then the validation errors will be suppressed, otherwise validation errors are shown.


validationMessage

XMLSpyDocumentEditor.validationMessage

Declaration: validationMessage as String

Description

If the validation failed (after a call to ValidateDocument) this property stores a string with the error message.


validationBadData

XMLSpyDocumentEditor.validationBadData

Declaration: validationBadData as XMLData

Description

If the validation failed (after a call to ValidateDocument) this property holds a reference to the XML element which causes the error.


DesignDataLoadObject

XMLSpyDocumentEditor.DesignDataLoadObject

Declaration: DesignDataLoadObject as XMLSpyXMLLoadSave

Description

The DesignDataLoadObject contains a reference to the SPS document. The SPS document is used to generate the WYSIWYG editing environment and is typically generated by XMLSpy XSLT Designer.

See also SchemaLoadObject for an example.


IsEditClearEnabled

XMLSpyDocumentEditor.IsEditClearEnabled

Declaration: IsEditClearEnabled as Boolean

Description

True if EditClear is possible.

See also Editing operations.


IsEditCopyEnabled

XMLSpyDocumentEditor.IsEditCopyEnabled

Declaration: IsEditCopyEnabled as Boolean

Description

True if copy to clipboard is possible.

See also EditCopy and Editing operations.


IsEditCutEnabled

XMLSpyDocumentEditor.IsEditCutEnabled

Declaration: IsEditCutEnabled as Boolean

Description

True if EditCut is currently possible.

See also Editing operations.


IsEditPasteEnabled

XMLSpyDocumentEditor.IsEditPasteEnabled

Declaration: IsEditPasteEnabled as Boolean

Description

True if EditPaste is possible.

See also Editing operations.


IsEditRedoEnabled

XMLSpyDocumentEditor.IsEditRedoEnabled

Declaration: IsEditRedoEnabled as Boolean

Description

True if EditRedo is currently possible.

See also Editing operations.


IsEditUndoEnabled

XMLSpyDocumentEditor.IsEditUndoEnabled

Declaration: IsEditUndoEnabled as Boolean

Description

True if EditUndo is possible.

See also Editing operations.


IsFindNextEnabled

XMLSpyDocumentEditor.IsFindNextEnabled

Declaration: IsFindNextEnabled as Boolean

Description

True if FindNext is currently possible. False if no more occurances are left.

See also Find and replace and FindDialog.


IsRowAppendEnabled

XMLSpyDocumentEditor.IsRowAppendEnabled

Declaration: IsRowAppendEnabled as Boolean

Description

True if RowAppend is possible.

See also Row operations.


IsRowDeleteEnabled

XMLSpyDocumentEditor.IsRowDeleteEnabled

Declaration: IsRowDeleteEnabled as Boolean

Description

True if RowDelete is possible.

See also Row operations.


IsRowDuplicateEnabled

XMLSpyDocumentEditor.IsRowDuplicateEnabled

Declaration: IsRowDuplicateEnabled as Boolean

Description

True if RowDuplicate is currently possible.

See also Row operations.


IsRowInsertEnabled

XMLSpyDocumentEditor.IsRowInsertEnabled

Declaration: IsRowInsertEnabled as Boolean

Description

True if RowInsert is possible.

See also Row operations.


IsRowMoveDownEnabled

XMLSpyDocumentEditor.IsRowMoveDownEnabled

Declaration: IsRowMoveDownEnabled as Boolean

Description

True if RowMoveDown is currently possible.

See also Row operations.


IsRowMoveUpEnabled

XMLSpyDocumentEditor.IsRowMoveUpEnabled

Declaration: IsRowMoveUpEnabled as Boolean

Description

True if RowMoveUp is possible.

See also Row operations.


LicCompany

XMLSpyDocumentEditor.LicCompany

Declaration: LicCompany as String

Description

LicCompany stores the company name of the license information.


LicFile

XMLSpyDocumentEditor.LicFile

Declaration: LicFile as String

Description

LicFile holds the file name if you use server bound license information.

See also LicServer and License information.


LicKey

XMLSpyDocumentEditor.LicKey

Declaration: LicKey as String

Description

LicKey stores the license key.


LicServer

XMLSpyDocumentEditor.LicServer

Declaration: LicServer as String

Description

LicServer holds the server name if you use server bound license information.

See also LicFile and License information.


LicUser

XMLSpyDocumentEditor.LicUser

Declaration: LicUser as String

Description

LicUser holds the user name of the license information.


SchemaLoadObject

XMLSpyDocumentEditor.SchemaLoadObject

Declaration: SchemaLoadObject as XMLSpyXMLLoadSave

Description

The SchemaLoadObject contains an reference to the XML Schema document for the current XML file. The Schema document is typically generated using XMLSpy.

Example

   objPlugIn.SchemaLoadObject.URL = "http://plugin.xmlspy.com/OrgChart.xml"
   objPlugIn.XMLDataLoadObject.URL = "http://plugin.xmlspy.com/OrgChart.xml"
   objPlugIn.DesignDataLoadObject.URL = "http://plugin.xmlspy.com/OrgChart.sps"
   objPlugIn.StartEditing

The code above sets all URL properties of the load objects and calls StartEditing to load and display the files. The current content and status of the plugin will be cleared.


XMLDataLoadObject

XMLSpyDocumentEditor.XMLDataLoadObject

Declaration: XMLDataLoadObject as XMLSpyXMLLoadSave

Description

The XMLDataLoadObject contains an reference to the XML document being edited. The XML document is typically defined using XMLSpy, but generated using a database or another business process.

See also SchemaLoadObject for an example.


XMLDataSaveUrl

XMLSpyDocumentEditor.XMLDataSaveUrl

Declaration: XMLDataSaveUrl as String

Description

When the XML data has been modified it is possible to save the data back to a server using an URL. This property defines the location where the XML data will be saved.

See also the XMLSpyDocumentEditor.Save and the XMLSpyDocumentEditor.SavePOST methods.


XMLRoot

XMLSpyDocumentEditor.XMLRoot

Declaration: XMLRoot as XMLData

Description

XMLRoot is the parent element of the currently displayed XML structure. Using the XMLData interface you have full access to the complete content of the file.

See also Using XMLData for more informations.


SelectionChanged

XMLSpyDocumentEditor.SelectionChanged

Declaration: SelectionChanged as VT_0019

Description

This event is raised whenever the user changes the current selection.


GetPreviousVisible

XMLSpyDocumentEditor.GetPreviousVisible

Declaration: GetPreviousVisible(pElement as XMLData) as XMLData

Description

The method gets the previous visible XML element in the document.


GetNextVisible

XMLSpyDocumentEditor.GetNextVisible

Declaration: GetNextVisible(pElement as XMLData) as XMLData

Description

The method gets the next visible XML element in the document.


SelectionMoveTabOrder

XMLSpyDocumentEditor.SelectionMoveTabOrder

Declaration: SelectionMoveTabOrder(bForward as Boolean,bTag as Boolean)

Description

SelectionMoveTabOrder() moves the current selection forwards or backwards.

If bTag is false and the current selection is at the last cell of a table a new line will be added.


SelectionSet

XMLSpyDocumentEditor.SelectionSet

Declaration: SelectionSet(pStartElement as XMLData,nStartPos as long,pEndElement as XMLData,nEndPos as long) as Boolean

Description

Use SelectionSet() to set a new selection in the Document Editor view. Its possible to set pEndElement to null (nothing) if the selection should be just over one (pStartElement) XML element.


CurrentSelection

XMLSpyDocumentEditor.CurrentSelection

Declaration: CurrentSelection as DocEditSelection

Description

The property provides access to the current selection in the Document Editor view.

The example code below retrieves the complete text of the current selection:

JavaScript:

   // somewhere in your script:
   GetSelection(objPlugIn.CurrentSelection);

   // GetSelection() collects complete text selection
   function GetSelection(objSel)
   {
      var strText = "";

      var objCurrent = objSel.Start;

      while(!objSel.End.IsSameNode(objCurrent))
      {
         objCurrent = objPlugIn.GetNextVisible(objCurrent);
         strText += objCurrent.TextValue;
      }

      strText += objSel.End.TextValue.substring(0,objSel.EndTextPosition);
      return objSel.Start.TextValue.substr(objSel.StartTextPosition) + strText;
   }


GetAllowedElements

XMLSpyDocumentEditor.GetAllowedElements

Declaration: GetAllowedElements(nAction as DOCEDElementActions,pStartElement as XMLData,pEndElement as XMLData,pElements as Variant)

Description

GetAllowedElements() returns the allowed elements for the various actions specified by nAction. Valid values for nAction are:

k_ActionInsertAt = 0
k_ActionApply = 1
k_ActionRemoveSurr = 2
k_ActionAppend = 3
k_ActionInsertBefore = 4

JavaScript example:

   function GetAllowed()
   {
      var objView = Application.ActiveDocument.DocEditView;

      var arrElements = new Array(1);

      var objStart = objView.CurrentSelection.Start;
      var objEnd = objView.CurrentSelection.End;

      var strText;
      strText = "valid elements at current selection:\n\n";

      for(var i = 1;i <= 4;i++)   {
         objPlugIn.GetAllowedElements(i,objStart,objEnd,arrElements);
         strText = strText + ListArray(arrElements) + "------------------\n";
      }

      return strText;
   }

   function ListArray(arrIn)
   {
      var strText = "";

      if(typeof(arrIn) == "object")   {
         for(var i = 0;i <= (arrIn.length - 1);i++)
            strText = strText + arrIn[i] + "\n";
      }

      return strText;
   }

VBScript example:

   Sub DisplayAllowed
      dim objView
      set objView = Application.ActiveDocument.DocEditView

      dim arrElements()

      dim objStart
      dim objEnd
      set objStart = objView.CurrentSelection.Start
      set objEnd = objView.CurrentSelection.End

      dim strText
      strText = "valid elements at current selection:" & chr(13) & chr(13)

      dim i

      For i = 1 To 4
         objView.GetAllowedElements i,objStart,objEnd,arrElements
         strText = strText & ListArray(arrElements) & "---------------" & chr(13)
      Next

      msgbox strText
   End Sub

   Function ListArray(arrIn)
      dim strText

      If IsArray(arrIn) Then
         dim i

         For i = 0 To UBound(arrIn)
            strText = strText & arrIn(i) & chr(13)
         Next
      End If

      ListArray = strText
   End Function


attachCallBack

XMLSpyDocumentEditor.attachCallBack

Declaration: attachCallBack(bstrName as String,varCallBack as Variant)

Description

The Document Editor PlugIn provides events which can be handled using custom callback functions. All event handlers take no parameters and any returned value will be ignored. To retrieve information when a specific event is raised you have to read the according properties of the event object.

List of currently available events:

ondragover
ondrop
onkeydown
onkeyup
onkeypressed
onmousemove
onbuttonup
onbuttondown
oncontextmenu
oneditpaste
oneditcut
oneditcopy
oneditclear

JavaScript example:

   // somwhere in your script:
   objPlugIn.attachCallBack("ondragover",OnDragOver);
   objPlugIn.attachCallBack("ondrop",OnDrop);

   // event handlers
   function OnDragOver()
   {
      if(   !objPlugIn.event.dataTransfer.ownDrag &&
         objPlugIn.event.dataTransfer.type == "TEXT"))
      {
         objPlugIn.event.dataTransfer.dropEffect = 1;
         objPlugIn.event.cancelBubble = true;
      }
   }

   // OnDrop() replaces the complete text value of the XML
   // element with the selection from the drag operation
   function OnDrop()
   {
      var objTransfer = objPlugIn.event.dataTransfer;

      if(   !objTransfer.ownDrag &&
         (objTransfer.type == "TEXT"))
         objPlugIn.event.srcElement.TextValue = objTransfer.getData();
   }


event

XMLSpyDocumentEditor.event

Declaration: event as DocEditEvent

Description

The event property holds a DocEditEvent object which contains informations about the current event.


DocEditSelection

DocEditSelection

Properties

Start
StartTextPosition
End
EndTextPosition


Start

DocEditSelection.Start

Declaration: Start as XMLData

Description

XML element where the current selection starts.


StartTextPosition

DocEditSelection.StartTextPosition

Declaration: StartTextPosition as long

Description

Position in DocEditSelection.Start.TextValue where the selection starts.


End

DocEditSelection.End

Declaration: End as XMLData

Description

XML element where the current selection ends.


EndTextPosition

DocEditSelection.EndTextPosition

Declaration: EndTextPosition as long

Description

Position in DocEditSelection.End.TextValue where the selection ends.


DocEditEvent

Properties

altKey
altLeft
ctrlKey
ctrlLeft
shiftKey
shiftLeft

keyCode
repeat

button

clientX
clientY

dataTransfer

srcElement
fromElement

propertyName

cancelBubble
returnValue

type

Description

DocEditEvent interface.


altKey

DocEditEvent.altKey

Declaration: altKey as Boolean

Description

True if the right ALT key is pressed.


altLeft

DocEditEvent.altLeft

Declaration: altLeft as Boolean

Description

True if the left ALT key is pressed.


ctrlKey

DocEditEvent.ctrlKey

Declaration: ctrlKey as Boolean

Description

True if the right CTRL key is pressed.


ctrlLeft

DocEditEvent.ctrlLeft

Declaration: ctrlLeft as Boolean

Description

True if the left CTRL key is pressed.


shiftKey

DocEditEvent.shiftKey

Declaration: shiftKey as Boolean

Description

True if the right SHIFT key is pressed.


shiftLeft

DocEditEvent.shiftLeft

Declaration: shiftLeft as Boolean

Description

True if the left SHIFT key is pressed.


keyCode

DocEditEvent.keyCode

Declaration: keyCode as long

Description

Keycode of the currently pressed key.

This property is read-write.


repeat

DocEditEvent.repeat

Declaration: repeat as Boolean

Description

True if the onkeydown event is repeated.


button

DocEditEvent.button

Declaration: button as long

Description

Specifies which mouse button is pressed:

0 No button is pressed.
1 Left button is pressed.
2 Right button is pressed.
3 Left and right buttons are both pressed.
4 Middle button is pressed.
5 Left and middle buttons both are pressed.
6 Right and middle buttons are both pressed.
7 All three buttons are pressed.

The onbuttondown and onbuttonup events set the button value in different ways. The onbuttonup event just sets the value for the button which has been released and raised the up event regardless which buttons are also pressed at the moment.


clientX

DocEditEvent.clientX

Declaration: clientX as long

Description

X value of the current mouse position in client coordinates.


clientY

DocEditEvent.clientY

Declaration: clientY as long

Description

Y value of the current mouse position in client coordinates.


dataTransfer

DocEditEvent.dataTransfer

Declaration: dataTransfer as Variant

Description

property dataTransfer


srcElement

DocEditEvent.srcElement

Declaration: srcElement as Variant

Description

Element which fires the current event.

This is usually an XMLData object.


fromElement

DocEditEvent.fromElement

Declaration: fromElement as Variant

Description

Currently no event sets this property.


propertyName

DocEditEvent.propertyName

Declaration: propertyName as String

Description

Currently no event sets this property.


cancelBubble

DocEditEvent.cancelBubble

Declaration: cancelBubble as Boolean

Description

Set cancelBubble to TRUE if the default event handler should not be called.


returnValue

DocEditEvent.returnValue

Declaration: returnValue as Variant

Description

Use returnValue to set a return value for your event handler.


type

DocEditEvent.type

Declaration: type as String

Description

Currently no event sets this property.


DocEditDataTransfer

Methods

getData

Properties

dropEffect
ownDrag
type

Description

DocEditDataTransfer interface.


getData

DocEditDataTransfer.getData

Declaration: getData as Variant

Description

getData gets the actual data associated with this dataTransfer object. See also DocEditDataTransfer.type for more informations.


dropEffect

DocEditDataTransfer.dropEffect

Declaration: dropEffect as long

Description

The property stores the drop effect from the default event handler. You can set the drop effect if you change this value and set DocEditEvent.cancelBubble to TRUE.


ownDrag

DocEditDataTransfer.ownDrag

Declaration: ownDrag as Boolean

Description

The property is TRUE if the current dragging source comes from inside of the Document Editor view.


type

DocEditDataTransfer.type

Declaration: type as String

Description

Holds the type of the data you get with the DocEditDataTransfer.getData method.

Currently supported data types are:

OWN data from Document Editor PlugIn itself
TEXT plain text
UNICODETEXT plain text as UNICODE


XMLSpyXMLLoadSave

Properties

String
URL

Description

The XMLSpyXMLLoadSave object is used to set the source for the files you need to load. You can either set the content directly via the String property or as an external location via the URL property.

See also XMLSpyDocumentEditor.SchemaLoadObject, XMLSpyDocumentEditor.DesignDataLoadObject and XMLSpyDocumentEditor.XMLDataLoadObject for more informations about how to use them.


String

String

Declaration: String as String

Description

You can use this property to set the XML structure from a string. The URL property of the object must be empty if you want to use this property.


URL

URL

Declaration: URL as String

Description

The property should contain a valid URL for the load or save operation. Currently supported HTTP protocols are http, https, ftp and gopher.

Previous Top