Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Friday, October 30, 2009

Alternative method to open a webpage from Ax

When you want to show your users a webpage from within Ax, you can use the ShellExecute command. Like this

WinApi::shellExecute('www.blogger.com');

You can use this format to open/show a specific XML file from disk as well. Like this:

WinApi::shellExecute('yourfile.xml','',@'C:\XMLFolder');

This will fire up your XML editor/viewer (possibly MS Internet Explorer) and display the specified file.
As an alternative, you can use the infolog for this as well. Like this:

infoLog.urlLookup('www.blogger.com');

or

infoLog.urlLookup(@'C:\XMLFolder\yourfile.xml');

This alternative method does not require extended security measures, like required when you use the WinAPI functions.

Monday, August 17, 2009

Create a XML file in Ax

This blog post is dedicated to XML files. A simple example, showing you how to create an XML file. Luckily, Ax already contains the framework to create an XML file, so it can do most of our work.


static void XML_Basic(Args _args)
{ XMLDocument xmlDoc;
XMLNode nodeRoot, commentNode;

XMLNode PanelNode;

XMLNode LengthNode;
XMLNode WidthNode;

FileName xmlFileName;

;

// create XML
xmlDoc = XMLDocument::newBlank();
nodeRoot = xmlDoc.documentElement();

// create XML nodes
commentNode = xmlDoc.appendChild(xmlDoc.createComment('Comment'));
commentNode.text('XML file from
http://dynamics-ax-live.blogspot.com');

PanelNode = xmlDoc.appendChild(xmlDoc.createElement('Panel'));
LengthNode = PanelNode.appendChild(xmlDoc.createElement('Length'));
LengthNode.text('2440');
WidthNode = PanelNode.appendChild(xmlDoc.createElement('Width'));

WidthNode.text('1220');

// write XML to file
xmlFileName=@'C:\MyXML.XML';
new FileIoPermission(xmlFileName, 'rw').assert();
xmlDoc.save(xmlFileName);
CodeAccessPermission::revertAssert();}


There are 3 basic steps in this small 'tutorial'. Step 1, create the XML document. Step 2, add the XML nodes. And step 3, save the XML document in a file. This example will create a very basic XML file, which introduces you to the world of tags, elements and attributes.






As XML files are a common way of exchanging information, you may want to get familiar to the terminology over here.