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 :
Finance | Project Operations, Human Resources, ...
Answered

Deserialize XML file

(0) ShareShare
ReportReport
Posted on by 390

Hey team,

I want to deserialize an XML file and extract the file name through x . Which function can I use to deserialize  the XML file to extract the file name? I saw an example but it uses a function which is dependent on Form Class which I don't want. Please can you help me with my issue.

Example I saw:

var classImported = FormRunConfigurationClass::deserialize(file, docuvalue.FileName);

I have the same question (0)
  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi skd,

    Do you want to deserialize XML file stored in document management to extract some values from the content?

  • skd Profile Picture
    390 on at

    Hey Sergei Minozhenko,

    The XML file is stored in the Docuref table.

    The code I referred to read the selected XML file from DocuRef and DocuValue Table. Now I want to deserialize the XML file to get the file name. How can I get it via x ?

    XmlDocument     xmlDoc = new XmlDocument();
            Filename filepath;
            Filename filename;
            Filename fileType;
            str fileNameString;
            DocuRef docuref;
            DocuValue   docuvalue;
    
            select firstonly docuref
                where docuref.recId == _docuRef.RecId
                join docuvalue
                    where docuvalue.recid == docuref.ValueRecId;
    
            DocuAction act = docuref.docuAction();
    
            System.IO.StreamReader sr = new System.IO.StreamReader(act.getStream(docuref));
    
            str file = sr.ReadToEnd();

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi skd,

    You can use XMLDocument class to deserialize XML and find elements you are interested in.

    XmlDocument xmlDoc = XmlDocument::newFromStream(DocumentManagement::getAttachmentStream(docuRef));

    www.axaptapedia.com/XMLDocument_class

  • skd Profile Picture
    390 on at

    Hey Sergei Minozhenko,

    By using this I'm not able to fetch my docs. It is throwing null exception. Please can you guide me as what have I done wrong. I simply want to read the XML file and fetch and the Owner(File) name.

    This is how I wrote my code:

               Filename filepath;
                Filename filename;
                Filename fileType;
                str fileNameString;
                DocuRef docuref;
                DocuValue   docuvalue;
                Description name;
                XmlElement          OwnerValue;
                XmlNode xmlNode;
    
            while select * from docuref where docuref.RefTableId == 17136  join docuvalue
                    where docuvalue.recid == docuref.ValueRecId
            {
                
            XmlDocument xmlDoc = XmlDocument::newFromStream(DocumentManagement::getAttachmentStream(docuRef));
                
                  xmlNode = xmlDoc.getNamedElement('OwnerValue');
                info(strFmt("Owner Name: %1", xmlNode.nodeValue()));
                }

    my XML File:

    Screenshot-_2800_152_2900_.png

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi skd,

    First, you need to find "FormRunConfigurationSerializer" element and in the found element, you need to find "OwnerValue" element

    xmlNode = xmlDoc.getNamedElement('FormRunConfigurationSerializer').getNamedElement('OwnerValue');

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi skd,

    Also, use "text" method to get element value. NodeValue returns null for element node types.

    info(strFmt("Owner Name: %1", xmlNode.text()));

  • skd Profile Picture
    390 on at

    Hey Sergei Minozhenko,

    Thank you so much. It worked for me.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans