SQLEncodeElement
Guide to Encoding / Decoding XML for storage in a database
Index > Books > Declarative Development Guide > Reference Library > Accessor Listing > SQLEncodeElement

Rate this page:
Really useful
Satisfactory
Not helpful
Confusing
Incorrect
Unsure
Extra comments:


Module

urn:org:ten60:netkernel:mod:db

Definition

Active URI Base

active:SQLEncodeElement/SQLDecodeElement

Format

<instr>
  <type>SQLEncodeElement</type>
  <operand>var:source</operand>
  <operator>
    <xpath>/path/to/element</xpath>
  </operator>
  <target>var:encoded</target>
</instr>

Syntax

ArgumentRulesDescription
typeMandatory SQLEncodeElement/SQLDecodeElement
operandMandatory the URI of the XML resources
targetMandatory Fragment OKtarget resource

It is often useful to store an XML fragment in a relational database text field.

The SQLEncodeElement/SQLDecodeElement accessor encode/decodes XML to/from a form suitable for storage in a text field of an RDBMS.

Encoding/Decoding is applied to one or multiple elements by specifying the canonical XPath target in the operator.

SQLEncodeElement

SQLEncodeElement serializes an XML fragment located by the canonical XPATH specified in the operator. The element, it's text and all it's child nodes are serialized into escaped text. The elements content becomes the serialized text. All child elements are removed. SQLEncodeElement serializes and collapses to escaped text an XML fragment. The element's text is suitable for storing in a RDBMS text field.

Example

For a source document var:source

<root>  <a>    <b>text</b>
  </a>
</root>

Element /root/a is encoded with...

<instr>
  <type>SQLEncodeElement</type>
  <operand>var:source</operand>
  <operator>
    <xpath>/root/a</xpath>
  </operator>
  <target>var:encoded</target>
</instr>

Producing the encoded document...

<root>  <a> &amp;lt;a&amp;gt; &amp;lt;b&amp;gt;text&amp;lt;/b&amp;gt; &amp;lt;/a&amp;gt; </a>
</root>

SQLDecodeElement

SQLDecodeElement parses a text element and replaces a text element located by the canonical XPATH specified in the operator. The element's text is parsed to an XML fragment. The fragment replaces the text element. SQLDecodeElement inflates an escaped text XML fragment.

Example

The encoded document above is decoded with

<instr>
  <type>SQLDecodeElement</type>
  <operand>var:encoded</operand>
  <operator>
    <xpath>/root/a</xpath>
  </operator>
  <target>var:decoded</target>
</instr>

Producing the original

<root>  <a>    <b>text</b>
  </a>
</root>
© 2003-2005, 1060 Research Limited. 1060 registered trademark, NetKernel trademark of 1060 Research Limited.