Websydian v6.1 online documentationOnline documentation - Websydian v6.5

Load Document from String

Introduction

This document describes how you can load an XML document that you have in a string instead of in a file.

In some cases the XML document you want to handle is not saved in a file, but instead present in the program in a string field.

One example of such a case would be if the "real" XML document was present as C-data in an element in another document. After reading the data from the enclosing document, you would have the "real" document as a string in a Plex field.

In such a case, you could start by saving the string to a file and then load the file using the DomServices.LoadDocumentFromFile function. This is the default behavior of the ImportXmlDocument function.

However, you have the option to load the string without saving it to a file first.

This document will describe how you can adjust an ImportXMLDocument function so that you can specify a string that should be loaded instead of a file.

Changing the ImportXMLDocument function

You need to create a field that can contain the document.

Let this field inherit from the FileName field that is part of the interface of the ImportXMLDocument function. This makes any manual changes to the parameter mappings inside the import function unnecessary.

Create a new function that inherits from ImportXMLDocument and replace the FileName field with the one you have created and the LoadDocumentFromFile function with the LoadDocumentFromString function.

This can be done as follows:

Source Object Verb Target Object
XMLDocumentString is a FLD WSYDOM/FileName
ImportXMLFromString is a FNC WSYXML/ImportXMLDocument
ImportXMLFromString replaces FNC

...by FNC

WSYDOM/DomServices.LoadDocumentFromFile

WSYDOM/DomServices.LoadDocumentFromString

ImportXMLFromString replaces FLD

...by FLD

WSYDOM/FileName

XMLDocumentString

Doing so replaces the function that would normally load the document from a file and instead it now loads the document from a string contained in the XMLDocumentString input parameter field.

Enter the handling of the document in the "Process XML document" edit point - just as in the standard ImportXMLDocument function.