Axaptapedia is now maintained by AgileCadence For more information please click here.

Load Web Documents

From Axaptapedia
Jump to: navigation, search

Loading web documents is easy using Microsoft .NET Framework in Dynamics AX. All necessary classes are implemented in System.IO Namespace and ready to use in Dynamics AX. For example reading the HTML document from can be done in this way:

<xpp> System.Net.WebRequest request = System.Net.WebRequest::Create(""); System.Net.WebResponse response; System.IO.StreamReader reader; System.IO.Stream stream; System.String line;

response = request.GetResponse(); stream = response.GetResponseStream(); reader = new System.IO.StreamReader(stream); line = reader.ReadLine(); while(line != null) {

   line = reader.ReadLine();


reader.Close(); </xpp>

or shorter (using WebClient class)

<xpp> public static void TEST_DownloadString (Args _args) {

   System.Net.WebClient webClient = new System.Net.WebClient();

} </xpp>

Example using proxy and credentials (via masia) <xpp>

  System.Net.WebClient         webClient = new System.Net.WebClient();
  System.Net.WebProxy          webProxy  = new System.Net.WebProxy("proxy");
  str                          s;
  webClient.set_Credentials(new System.Net.NetworkCredential("user", "password"));
  s = webClient.DownloadString("url")


Loading XML document

While XML is the default industry standard for data exchange, it is simple to load published XML documents. News Feeds are published as XML documents that are interpreted by a browser or mail client like outlook to provide a convenient user interface. To handle XML documents add the System.Xml namespace at the AOT. <xpp> static void Job8(Args _args) {

   XmlDocument doc = new XMLDocument();
   XmlNodeList nodeList;
   XMLElement element;
   nodeList = doc.selectNodes(@'//item');
   for(element = nodeList.nextNode(); element; element = nodeList.nextNode())

} </xpp>