<h1>com::mxgraph::mxCodec Class Reference</h1><!-- doxytag: class="com::mxgraph::mxCodec" -->
<p>XML codec for .NET object graphs. In order to resolve forward references when reading files the XML document that contains the data must be passed to the constructor.
<ahref="#_details">More...</a></p>
<p><ahref="classcom_1_1mxgraph_1_1mxCodec-members.html">List of all members.</a></p>
<tableborder="0"cellpadding="0"cellspacing="0">
<tr><tdcolspan="2"><h2>Public Member Functions</h2></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Constructs an XML encoder/decoder with a new owner document. <ahref="#a08aed19305c14248949292a713588056"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Constructs an XML encoder/decoder for the specified owner document. The document is required to resolve forward ID references. This means if you parse a graphmodel that is represented in XML you must also pass the document that contains the XML to the constructor, otherwise forward references will not be resolved. <ahref="#a56834df37ac58e69c1445e14c0c8dcb7"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Assoiates the given object with the given ID. <ahref="#ab7189e0c130a648ef15541f2be790bd9"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the decoded object for the element with the specified ID in document. If the object is not known then lookup is used to find an object. If no object is found, then the element with the respective ID from the document is parsed using decode. <ahref="#ac4c7937c86766f1cf44f12d4023d706d"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Hook for subclassers to implement a custom lookup mechanism for cell IDs. This implementation always returns null. <ahref="#adcf61362787457dc4ed50811871571f8"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the element with the given ID from the document. <ahref="#ab75670c8e89934b2f45cb202a95598b8"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the element with the given ID from document. The optional attr argument specifies the name of the ID attribute. Default is id. The XPath expression used to find the element is //*[@id='arg'] where id is the name of the ID attribute (attributeName) and arg is the given id. <ahref="#afa470c9e8ffc3d563b62aa46a619607d"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the ID of the specified object. This implementation calls reference first and if that returns null handles the object as an <aclass="el"href="classcom_1_1mxgraph_1_1mxCell.html"title="Cells are the elements of the graph model. They represent the state of the groups...">mxCell</a> by returning their IDs using mxCell.getId. If no ID exists for the given cell, then an on-the-fly ID is generated using mxCellPath.create. <ahref="#af13936ced2b0da9ad4f088db31ca2007"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Hook for subclassers to implement a custom method for retrieving IDs from objects. This implementation always returns null. <ahref="#a65dacbf11b9be370b293b8256ef116fe"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Encodes the specified object and returns the resulting XML node. <ahref="#aed5b7fe6bb0431767d3a0303822d092e"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Decodes the given XML node using decode(XmlNode, Object). <ahref="#a270c02410861862c8c08e0d45c4b4dbf"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Decodes the given XML node. The optional "into" argument specifies an existing object to be used. If no object is given, then a new instance is created using the constructor from the codec. The function returns the passed in object or the new instance if no object was given. <ahref="#ad0b4d9980bf37c9a7dd75032eb943f52"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Encoding of cell hierarchies is built-into the core, but is a higher-level function that needs to be explicitely used by the respective object encoders (eg. <aclass="el"href="classcom_1_1mxgraph_1_1mxModelCodec.html"title="Codec for mxGraphModels. This class is created and registered dynamically at load...">mxModelCodec</a>, mxChildChangeCodec and mxRootChangeCodec). This implementation writes the given cell and its children as a (flat) sequence into the given node. The children are not encoded if the optional includeChildren is false. The function is in charge of adding the result into the given node and has no return value. <ahref="#a063a0154505235fab267d75f87d1d94e"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Decodes cells that have been encoded using inversion, ie. where the user object is the enclosing node in the XML, and restores the group and graph structure in the cells. Returns a new <aclass="el"href="classcom_1_1mxgraph_1_1mxCell.html"title="Cells are the elements of the graph model. They represent the state of the groups...">mxCell</a> instance that represents the given node. <ahref="#a2e31c56e464eabd8fe784f93ebf45b78"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Inserts the given cell into its parent and terminal cells. <ahref="#a0c731bec8adf1279a5813e9334b37319"></a><br/></td></tr>
<tr><tdcolspan="2"><h2>Static Public Member Functions</h2></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Sets the attribute on the specified node to value. This is a helper method that makes sure the attribute and value arguments are not null. <ahref="#a155ebb610b21e83dfc28eb30ace11dfa"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Holds the owner document of the codec. <ahref="#a91caf2d5796965cfeae55e748ae1d438"></a><br/></td></tr>
<tr><tdclass="memItemLeft"align="right"valign="top">Dictionary< string, object > </td><tdclass="memItemRight"valign="bottom"><aclass="el"href="classcom_1_1mxgraph_1_1mxCodec.html#a9f983ce7275a1005de496ee15093a6f0">objects</a> = new Dictionary<string, Object>()</td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Maps from IDs to objects. <ahref="#a9f983ce7275a1005de496ee15093a6f0"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Specifies if default values should be encoded. Default is false. <ahref="#a955dde36b094d0845613ff7b7b0abdb9"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Sets or returns the owner document of the codec. <ahref="#a3c424b0a7288e6e8a4029c06ec358009"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Sets or returns if default values of member variables should be encoded. <ahref="#a3f063598603020bfdd63c9b3a24ebe97"></a><br/></td></tr>
<p>XML codec for .NET object graphs. In order to resolve forward references when reading files the XML document that contains the data must be passed to the constructor. </p>
<hr/><h2>Constructor & Destructor Documentation</h2>
<p>Constructs an XML encoder/decoder for the specified owner document. The document is required to resolve forward ID references. This means if you parse a graphmodel that is represented in XML you must also pass the document that contains the XML to the constructor, otherwise forward references will not be resolved. </p>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"></td><tdvalign="top"><em>document</em> </td><td>Optional XML document that contains the data. If no document is specified then a new document is created using mxUtils.createDocument</td></tr>
<p>Decodes the given XML node. The optional "into" argument specifies an existing object to be used. If no object is given, then a new instance is created using the constructor from the codec. The function returns the passed in object or the new instance if no object was given. </p>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"></td><tdvalign="top"><em>node</em> </td><td>XML node to be decoded.</td></tr>
<tr><tdvalign="top"></td><tdvalign="top"><em>into</em> </td><td>Optional object to be decodec into.</td></tr>
</table>
</dd>
</dl>
<dlclass="return"><dt><b>Returns:</b></dt><dd>Returns an object that represents the given node.</dd></dl>
<p>Decodes cells that have been encoded using inversion, ie. where the user object is the enclosing node in the XML, and restores the group and graph structure in the cells. Returns a new <aclass="el"href="classcom_1_1mxgraph_1_1mxCell.html"title="Cells are the elements of the graph model. They represent the state of the groups...">mxCell</a> instance that represents the given node. </p>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"></td><tdvalign="top"><em>node</em> </td><td>XML node that contains the cell data.</td></tr>
<tr><tdvalign="top"></td><tdvalign="top"><em>restoreStructures</em> </td><td>Boolean indicating whether the graph structure should be restored by calling insert and insertEdge on the parent and terminals, respectively. </td></tr>
</table>
</dd>
</dl>
<dlclass="return"><dt><b>Returns:</b></dt><dd>Graph cell that represents the given node.</dd></dl>
<p>Encoding of cell hierarchies is built-into the core, but is a higher-level function that needs to be explicitely used by the respective object encoders (eg. <aclass="el"href="classcom_1_1mxgraph_1_1mxModelCodec.html"title="Codec for mxGraphModels. This class is created and registered dynamically at load...">mxModelCodec</a>, mxChildChangeCodec and mxRootChangeCodec). This implementation writes the given cell and its children as a (flat) sequence into the given node. The children are not encoded if the optional includeChildren is false. The function is in charge of adding the result into the given node and has no return value. </p>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"></td><tdvalign="top"><em>cell</em> </td><td><aclass="el"href="classcom_1_1mxgraph_1_1mxCell.html"title="Cells are the elements of the graph model. They represent the state of the groups...">mxCell</a> to be encoded.</td></tr>
<tr><tdvalign="top"></td><tdvalign="top"><em>node</em> </td><td>Parent XML node to add the encoded cell into.</td></tr>
<tr><tdvalign="top"></td><tdvalign="top"><em>includeChildren</em> </td><td>Boolean indicating if the method should include all descendents</td></tr>
<p>Returns the element with the given ID from document. The optional attr argument specifies the name of the ID attribute. Default is id. The XPath expression used to find the element is //*[@id='arg'] where id is the name of the ID attribute (attributeName) and arg is the given id. </p>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"></td><tdvalign="top"><em>id</em> </td><td>ID of the element to be returned.</td></tr>
<tr><tdvalign="top"></td><tdvalign="top"><em>attributeName</em> </td><td>Optional string for the attributename. Default is id.</td></tr>
</table>
</dd>
</dl>
<dlclass="return"><dt><b>Returns:</b></dt><dd>Returns the element for the given ID.</dd></dl>
<p>Returns the ID of the specified object. This implementation calls reference first and if that returns null handles the object as an <aclass="el"href="classcom_1_1mxgraph_1_1mxCell.html"title="Cells are the elements of the graph model. They represent the state of the groups...">mxCell</a> by returning their IDs using mxCell.getId. If no ID exists for the given cell, then an on-the-fly ID is generated using mxCellPath.create. </p>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"></td><tdvalign="top"><em>obj</em> </td><td>Object to return the ID for.</td></tr>
</table>
</dd>
</dl>
<dlclass="return"><dt><b>Returns:</b></dt><dd>Returns the ID for the given object.</dd></dl>
<p>Returns the decoded object for the element with the specified ID in document. If the object is not known then lookup is used to find an object. If no object is found, then the element with the respective ID from the document is parsed using decode. </p>
<dl><dt><b>Parameters:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"></td><tdvalign="top"><em>id</em> </td><td>ID of the object to be returned.</td></tr>
</table>
</dd>
</dl>
<dlclass="return"><dt><b>Returns:</b></dt><dd>Returns the object for the given ID.</dd></dl>