Add XML Version and Soap:Body to XML Dom Doc

AR-11
Member Posts: 5
Hi! I am trying to create a simple XML file to test with a 3rd party product. I am running into two issues that I can't seem to resolve. I have read through so many forums and can't seem to find the answers.
1. When I create my XML file, the 'version="1.0" encoding="UTF-8"' is only exporting the Version=1.0. The Encoding is not showing in my file. I am currently using the DomDoc CreateProcessingInstruction
2. I can't get the Node "Soap:Body" to print no matter what I try. I don't have it anywhere in my code at this time because no matter what I tried, it did't work.
I am all new to XML coding so hopefully this is something simple to some of you out there.
Here is my code:
If anyone can help it will be greatly appreciated!
Thank you!
1. When I create my XML file, the 'version="1.0" encoding="UTF-8"' is only exporting the Version=1.0. The Encoding is not showing in my file. I am currently using the DomDoc CreateProcessingInstruction
2. I can't get the Node "Soap:Body" to print no matter what I try. I don't have it anywhere in my code at this time because no matter what I tried, it did't work.
I am all new to XML coding so hopefully this is something simple to some of you out there.
Here is my code:
IF ISCLEAR(XMLDOMDocument) THEN CREATE(XMLDOMDocument); IF ISCLEAR(XMLDocOut) THEN CREATE(XMLDocOut); DocNameSpace := ''; SoapEnvelope := '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' + 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope"/>'; XMLDomDocInst := XMLDOMDocument.createProcessingInstruction('xml','version="1.0" encoding="UTF-8"'); CurrNode := XMLDOMDocument.appendChild(XMLDomDocInst); XMLDOMDocument.loadXML := (SoapEnvelope); CurrNode := XMLDOMDocument.documentElement; AddElement(CurrNode,'testPing', 'xmlns="http://xxx"',DocNameSpace,NewChild); CurrNode := NewChild; AddElement(CurrNode,'apiKey','API_KEY_VALUE,DocNameSpace,NewChild); CurrNode := CurrNode.parentNode; XMLDOMDocument.save('C:\XMLBuffer\TEST.xml');
If anyone can help it will be greatly appreciated!
Thank you!
0
Comments
-
1. look at codeunit 680 "Style Sheet Management", more precise at function ConvertMailMergeToStyleSheet
2. a complete sample which works:PROCEDURE fct_CreateSOAPEnveloppe@1100095001(VAR pautXMLDom@1100095000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v4.0'.DOMDocument";ptxtFunction@1100095001 : Text[1024];VAR pautXMLFunctionNode@1100095005 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMNode";VAR pautXMLLoginNode@1100084000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMNode"); VAR lautsoapEnvelope@1100095004 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMElement"; lautsoapBody@1100095003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMElement"; lautsoapMethod@1100095002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMElement"; lautsoapInclReg@1100095007 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMElement"; lautProcessingInstruction@1100084001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF89-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMProcessingInstruction"; lautAttribute@1100084002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF85-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMAttribute"; lautNode@1100084003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMNode"; BEGIN //---------------------------------------------------------------------------------------------------------------------------------- // Create SOAP Envelope //---------------------------------------------------------------------------------------------------------------------------------- CLEAR(lautsoapEnvelope); lautsoapEnvelope := pautXMLDom.createElement('Soap:Envelope'); lautsoapEnvelope.setAttribute('xmlns:Soap', 'http://schemas.xmlsoap.org/soap/envelope/'); lautsoapEnvelope.setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); lautsoapEnvelope.setAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); pautXMLDom.appendChild(lautsoapEnvelope); //---------------------------------------------------------------------------------------------------------------------------------- // Create SOAP Body //---------------------------------------------------------------------------------------------------------------------------------- CLEAR(lautsoapBody); lautsoapBody := pautXMLDom.createElement('Soap:Body'); lautsoapEnvelope.appendChild(lautsoapBody); //---------------------------------------------------------------------------------------------------------------------------------- // Create Method Element //---------------------------------------------------------------------------------------------------------------------------------- CLEAR(lautsoapMethod); lautsoapMethod := pautXMLDom.createElement(ptxtFunction); lautsoapMethod.setAttribute('xmlns', 'http://transics.org'); lautsoapBody.appendChild(lautsoapMethod); //---------------------------------------------------------------------------------------------------------------------------------- // Add login and Function node //---------------------------------------------------------------------------------------------------------------------------------- lautsoapMethod.appendChild(pautXMLLoginNode); lautsoapMethod.appendChild(pautXMLFunctionNode); IF ptxtFunction = 'Get_ActivityReport_V5' THEN BEGIN lautsoapInclReg := pautXMLDom.createElement('IncludeRegistrations'); lautsoapInclReg.text := 'true'; lautsoapMethod.appendChild(lautsoapInclReg); END; lautNode := pautXMLDom.firstChild; lautProcessingInstruction := pautXMLDom.createProcessingInstruction('xml','version="1.0"'); lautAttribute := pautXMLDom.createAttribute('encoding'); lautAttribute.value := 'UTF-8'; lautProcessingInstruction.attributes.setNamedItem(lautAttribute); pautXMLDom.insertBefore(lautProcessingInstruction,lautNode); END;
Now, let's see what we can see.
...
Everybody on-line.
...
Looking good!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions