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)

create XML with XmlDocument and XmlElement

(0) ShareShare
ReportReport
Posted on by

Hi all

I have to create the following xmlstructure but whatever I do it looks different.

How can I get this one:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="schemas.xmlsoap.org/.../envelope" xmlns:ns1="http://tempuri.org/">
  <SOAP-ENV:Body>
    <ns1:Import>
      <ns1:request>
        <ns1:AuthenticationKey>?</ns1:AuthenticationKey>
        <ns1:Title>?</ns1:Title>
        <ns1:Comments>?</ns1:Comments>
        <ns1:File>Pw==</ns1:File>
        <ns1:Filename>?</ns1:Filename>
        <ns1:ImportType>?</ns1:ImportType>
        <ns1:SendStatusMail>true</ns1:SendStatusMail>
        <ns1:ApplicationUri>?</ns1:ApplicationUri>
        <ns1:ZipFile>Pw==</ns1:ZipFile>
        <ns1:ZipFilename>?</ns1:ZipFilename>
      </ns1:request>
    </ns1:Import>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>



*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    Could you be a bit more specific, please? Which part are you struggling with?

  • Community Member Profile Picture
    on at

    well as I discribed I cannot get the format .

    when I try to create the xml by code with XmlDocument and XmlElement class I get the following:

    <?xml version="1.0" encoding="utf-8"?>
    <Envelope xmlns:SOAP-ENV="schemas.xmlsoap.org/.../envelope" xmlns:ns1="http://tempuri.org/">
    	<Body>
    		<Import>
    			<AuthenticationKey />
    			<Title></Title>
    			<Comments>automatic exort from Dynamics AX</Comments>
    			<File><![CDATA[...]]></File>
    			<FileName>Employees_IN.xml</FileName>
    			<ImportType>StaffingXML</ImportType>
    			<SendStatusMail>false</SendStatusMail>
    		</Import>
    	</Body>


  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    You have many ways to do this. You could use .Net reflection to create the elements using the namespaces with which you could generate XML files. Alternatively you could just build the whole string yourself.

    Since you just want to use a SOAP-envelope, why don't you write the whole communication stuff in a C# Wrapper that you could just call in AX as a Reference?

    http://stackoverflow.com/questions/13779171/construct-soap-envelope-xml-using-c-sharp

  • Community Member Profile Picture
    on at

    well the xml itself is generated. I just can't get the namespace ns1 to the single elements

  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    All right, it seems that you know how to create elements and set values, but not how to work with namespaces.

    First of all, notice that the second argument of XMLDocument.createElement2() is namespace URI. If you want to say that, for instance, the namespace of the Import element is http://tempuri.org/, you should use this argument.

  • Community Member Profile Picture
    on at

    I tried that as well but than I get someting like this:

    <SOAPENV:Body xmlns:SOAPENV="SOAP-ENV">

    ...

    </SOAPENV:Body>

    but it should be

    <SOAPENV:Body>

    ...

    </SOAPENV:Body>

  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    xmlns:SOAPENV is an attribute named SOAPENV in a namespace with xmlns prefix, which has nothing to do with what you intended.

    Please show us your code.

  • Community Member Profile Picture
    on at


    Hi Martin

    I played around with it right now. Currently it look like this:



    str SOAPENV_ENV = ("schemas.xmlsoap.org/.../envelope"); str SOAPENV_NS = ("http://tempuri.org/"); System.Net.WebRequest request = null; System.Net.WebResponse response = null; XmlDocument soapDoc; XmlElement soapEnvelope; XmlElement soapHeader; XmlElement soapBody; XmlElement soapImport; XmlElement soapField; XmlElement soapInnerField; System.Xml.XmlWriter xmlWriter; System.IO.StreamWriter writer; System.IO.StreamReader reader; //System.Web.HttpResponse httpResponse; System.Exception netException; str result, errorText; Filename fPath; Filename fName; Filename fType; str fileNameString; ; [fPath, fName, fType] = fileNameSplit(this.parmFileName()); fileNameString = fName + fType; try { soapDoc = XmlDocument::newBlank(); soapDoc.createXmlDeclaration("1.0", "utf-8", ""); soapEnvelope = soapDoc.createElement("SOAP-ENV:Envelope"); soapEnvelope.setAttribute("xmlns:SOAP-ENV", SOAPENV_ENV); soapEnvelope.setAttribute("xmlns:ns1", SOAPENV_NS); soapBody = soapDoc.createElement("SOAP-ENV:Body"); //soapBody.prefix("SOAP-ENV"); soapImport = soapDoc.createElement("ns1:Import"); //soapImport.prefix("ns1"); soapField = soapDoc.createElement("AuthenticationKey"); soapField.prefix("ns1"); soapField.appendChild(soapDoc.CreateTextNode("")); soapImport.appendChild(soapField); soapField = soapDoc.createElement("ns1:Title"); soapField.appendChild(soapDoc.CreateTextNode("")); soapImport.appendChild(soapField);
  • Suggested answer
    Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    You get those attributes because that's what you put into your code. It seems that you don't know what a namespace is, am I right?

    I don't have time to go to theory right now, but you can look here how to add namespaces and their prefixes and I already told you how to specify namespaces when adding elements. And throw away those attributes.

  • Community Member Profile Picture
    on at

    well I am just to stupid for this but I still cannot get how to create xml nodes with just the Prefix of the namespace.

    But thanks for your help

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
Sukrut Parab Profile Picture

Sukrut Parab 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans