Importing XML using the Parse Action

Action: Parse

M/DB:X is unusual in that it does not use a validating XML parser. It will attempt to tidy up any XML or HTML that you import into it, and will construct its best attempt at a corresponding DOM from what it is given. This lenient parsing makes it ideal for importing "lazily"-specified HTML which you can then analyse, search and manipulate as a correctly-structured XML document.

Note 1: this lenient parsing does mean that the DOM constructed by M/DB:X may differ from what you expected when you imported a document, particularly if your document contains mismatched tags. However if M/DB:X is given a properly structured XML document, then it will accurately parse it and create a corresponding DOM.

Note 2: M/DB:X will validate JSON input and will reject it if it finds syntax errors

Action-specific name/value pairs:

Parameter Name Description
DocumentName The name that you want assigned to the document if parsing completes successfully. If a document of the same name exists in M/DB:X, it will be automatically deleted. The name is case-sensitive.
XML String of XML to import into M/DB:X as a new document. Note that the XML must be correctly URL-escaped.

Must not be present if JSON specified as an input.
JSON JSON string to import into M/DB:X where it will be converted to a new XML document. Note that the JSON must be correctly URL-escaped if necessary.

Must not be present if XML specified as an input.

Example Request

XML Input

Action=Parse
&DocumentName=myExample
&MDBAccessKeyId=[your access key id]
&Signature=[computed signature]
&SignatureMethod=HmacSHA256
&SignatureVersion=2
&Timestamp=2009-06-14T13%3A19%3A41
&Version=2009-04-15
&XML=%3CmyExample%3E%3CmyTag%20a%3D'1'%20b%3D'2'%3EHello%20world!%3C/myTag%3E%3C/myExample%3E
&db=mdbx

JSON Input

Action=Parse
&DocumentName=myJSONExample
&JSON=%7Banimals%3A%7Bdog%3A%5B%7Bname%3A%22Rufus%22%2Cbreed%3A%22labrador%22%7D%2C%7B
name%3A%22Marty%22%2Cbreed%3A%22whippet%22%7D%5D%2Ccat%3A%7Bname%3A%22Matilda%22%7D%7D%7D
&MDBAccessKeyId=[your access key id]
&OutputFormat=JSON
&Signature=[computed signature]
&SignatureMethod=HmacSHA256
&SignatureVersion=2
&Timestamp=2009-06-14T13%3A19%3A41
&Version=2009-04-15
&db=mdbx

In this example, the JSON input is:

{animals:{dog:[{name:"Rufus",breed:"labrador"},{name:"Marty",breed:"whippet"}],
  cat:{name:"Matilda"}}}

The resulting XML DOM that M/DB:X will create and store is:

<animals><dog><name>Rufus</name><breed>labrador</breed></dog><dog><name>Marty</name>
<breed>whippet</breed></dog><cat><name>Matilda</name></cat></animals>

Example Response

XML

<?xml version='1.0'?>
<ParseResponse xmlns="http://mdbx.mgateway.com/doc/2009-06-05/">
   <ParseResult>
      <DocumentOID>
         6-1
      </DocumentOID>
   </ParseResult>
</ParseResponse>

The XML was parsed without error and a DOM created with a DocumentOID of "6-1" and DocumentName of "myExample"

JSON (ie if OutputFormat=JSON specified in the Request)

{DocumentOID:"8-1"}

The JSON was parsed without error and converted to an XML DOM with a DocumentOID of "8-1" and DocumentName of "myJSONExample"