Home > Ax Technical > Storing and retrieving an XML in Resource node in Dynamics Ax

Storing and retrieving an XML in Resource node in Dynamics Ax

Resource node in Dynamics Ax can be used to store images, xml,  Gif files. In this article let’s see how to store and retrieve an Xml file in resource node through X++.

Read the xml from Resource node

private void initializeResourceNode()
{
    Xml                  loadXML;
    ResourceNode    gResNode;
    XmlDocument     gXml;
    ;
    //load element to resource node
    gResNode    = TreeNode::findNode(@'\Resources\SysVersionControlSystemMorphXDefFile');
   //load xml to co
    [loadXML]   = SysResource::getResourceNodeData(gResNode);
    gxml        = XMLDocument::newXml(loadXML);
}

Saving  the Xml after modifying contents

private void packResourceNode()
{
    TextBuffer      textBUffer;
    BinData         binData;
    ContainerClass  containerClass;
    ;

    //Load Xml to text buffer
    textBuffer = new TextBuffer();
    textBuffer.setText(gXml.xml());

    //Move it to container
    containerClass = new ContainerClass([[SysResourceType::XMLDoc],new ContainerClass([textBuffer.getText()]).toBlob()]);

   //Store container to bin data
    binData = new BinData();
    binData.setData(containerClass.toBlob());

   //Set data in resource node
    gResNode.AOTSetData(binData);
    gResNode.AOTsave();
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: