web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How do I read an XmlDataDocument into AX?

(0) ShareShare
ReportReport
Posted on by 120

Is it possible to return an XmlDataDocument from a .NET assembly to AX 4.0?

I have requirement to look at data from legacy systems and would rather re-use existing functionality than do a re-write. If this not possible what would be an appropriate alternative?

Thanks in advance...

*This post is locked for comments

I have the same question (0)
  • JasonW Profile Picture
    120 on at

    for anyone who is also looking to solve this problem - if you return the actual inner XML text you load this into an AX XMLDocument. The same techinque can be used to pass data back to .NET and into a dataset.

    .NET functions/methods:

        Public Function GetDotNetDataset(ByVal vTopCount As Integer) As String
            Dim DBConnection As SqlConnection = New SqlConnection(???)
            Dim adpGetData As New SqlDataAdapter("sp_GetMyData", DBConnection)
            Dim dstResults As New DataSet
            Dim xmlDoc As Xml.XmlDocument

            With adpGetData.SelectCommand
                .CommandType = CommandType.StoredProcedure
                .Parameters.Add("@TopCount", SqlDbType.Int).Value = vTopCount
            End With
            adpGetData.Fill(dstResults, "MYDATA")

            xmlDoc = New Xml.XmlDataDocument(dstResults)
            Return xmlDoc.InnerXml
        End Function

        Public Sub ReceiveXMLStringSaveDataset(ByVal vInnerXMLString As String)
            Dim dstAddress As New DataSet
            Dim xmlDoc As Xml.XmlDataDocument = New Xml.XmlDataDocument

            xmlDoc.InnerXml = vInnerXMLString
            dstAddress.ReadXml(New Xml.XmlNodeReader(xmlDoc))
            dstAddress.WriteXml("C:\temp\xmldataset.xml")
        End Sub

    X++ code:

    void GetDotNetData()
    {
        VBPassBackDataset.DBLookup myVBclass;
        XmlDocument xmlDOTNETdata;
        XmlNodeList nodeList;
        XmlNode node;
        str xmlText;

        myVBclass = new VBPassBackDataset.DBLookup();
        xmlDOTNETdata = new XmlDocument();

        xmlText = myVBclass.GetDotNetDataset(250);
        xmlDOTNETdata.loadxml(xmlText);

        nodeList = xmlDOTNETdata.documentElement().childNodes();

        do
        {
            node = nodeList.nextNode();
            if (node)
            {
                info( node.nodeName() + ':' + node.innerText());
            }
        } while(node);
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans