Hello, i make my code to create XML Sepa file, work fine!!!!! but have only one error, is write a attribute XMLNS and i can't remove, ex:
I need:
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance">
<CstmrCdtTrfInitn>
...
</CstmrCdtTrfInitn>
</Document>
But i give:
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance">
<CstmrCdtTrfInitn xmlns="">
...
</CstmrCdtTrfInitn>
</Document>
My code to create XML is:
CREATE(xmldoc,TRUE);
xmldoc.loadXML('<?xml version="1.0" encoding="UTF-8"?><Document></Document>');
xmlnode := xmldoc.documentElement;
AddAttribute(xmlnode,'xmlns:xsi','
http://www.w3.org/2001/XMLSchema-instance');
AddAttribute(xmlnode,'xmlns','urn:iso:std:iso:20022:tech:xsd:pain.001.001.03');
newnode := xmldoc.createNode(1,'CstmrCdtTrfInitn','');
xmlnode.appendChild(newnode);
xmlnode2 := xmlnode.selectSingleNode('CstmrCdtTrfInitn');
newnode := xmldoc.createNode(1,'GrpHdr','');
xmlnode2.appendChild(newnode);
...
Function AddAttribute:AddAttribute(VAR XMLAttNode : Automation "'Microsoft XML, v6.0'.IXMLDOMNode";AttributeName : Text[180];AttributeValue : Text[180])
NewAttributeNode := XMLAttNode.ownerDocument.createAttribute(AttributeName);
IF AttributeValue <> '' THEN BEGIN
NewAttributeNode.value := AttributeValue;
XMLAttNode.attributes.setNamedItem(NewAttributeNode);
END;
And my code used to try to remove attribute is:xmlread(ficheiro : Text[250])
ffile.OPEN(ficheiro);
ffile.CREATEINSTREAM(strInStream);
IF ISCLEAR(xmldomDoc) THEN CREATE(xmldomDoc);
xmldomDoc.load(strInStream);
xmldomDoc.getElementsByTagName('CstmrCdtTrfInitn').item(0).attributes.removeNamedItem('xmlns');
xmlNodeList := xmldomDoc.getElementsByTagName('CstmrCdtTrfInitn/PmtInf/PmtTpInf/CdtTrfTxInf');
FOR i:=0 TO xmlNodeList.length()-1 DO BEGIN
xmlNodeList.item(i).attributes.removeNamedItem('ID');
END;
ffile.CLOSE;
xmldomDoc.save(ficheiro);
the last funcion work fine to remove others attributes, but not for xmlns, please can give me illumination.
Thanks.
Answers
OBJECT Codeunit 50099 Test XML
{
OBJECT-PROPERTIES
{
Date=26/04/16;
Time=19:56:35;
Modified=Yes;
Version List=XML;
}
PROPERTIES
{
OnRun=BEGIN
GenerarXML();
END;
}
CODE
{
VAR
XMLDoc@1000000000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 3.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v3.0'.DOMDocument";
PROCEDURE GenerarXML@1000000020();
VAR
NewChild@1000000001 : ARRAY [10] OF Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 3.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v3.0'.IXMLDOMNode";
BEGIN
IF ISCLEAR(XMLDoc) THEN
CREATE(XMLDoc);
AppendProcessingInstruction(XMLDoc,'xml','version="1.0" encoding="utf-8"');
AppendElement(XMLDoc, 'Document', '', NewChild[1]);
AppendAttribute(NewChild[1], 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
AppendAttribute(NewChild[1], 'xmlns', 'urn:iso:std:iso:20022:tech:xsd:pain.001.001.03');
AppendElement(NewChild[1], 'CstmrCdtTrfInitn', '', NewChild[2]);
AppendElement(NewChild[2], 'GrpHdr', '', NewChild[3]);
XMLDoc.save('C:\TEMP\OUTCOME.XML');
END;
PROCEDURE AppendProcessingInstruction@1100007(Parent@1100000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 3.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v3.0'.IXMLDOMNode";Target@1100001 : Text[80];Data@1100002 : Text[250]);
VAR
ProcessingInstruction@1100003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 3.0:{2933BF89-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v3.0'.IXMLDOMProcessingInstruction";
BEGIN
ProcessingInstruction := XMLDoc.createProcessingInstruction(Target,Data);
Parent.appendChild(ProcessingInstruction);
END;
PROCEDURE AppendElement@1100009(Parent@1100000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 3.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v3.0'.IXMLDOMNode";Name@1100001 : Text[80];Value@1100002 : Text[250];VAR Element@1100003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 3.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v3.0'.IXMLDOMElement");
BEGIN
Element := XMLDoc.createElement(Name);
IF Value <> '' THEN
Element.text := Value;
Parent.appendChild(Element);
END;
PROCEDURE AppendAttribute@1100010(Parent@1100000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 3.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v3.0'.IXMLDOMElement";Name@1100001 : Text[80];Value@1100002 : Text[250]);
BEGIN
Parent.setAttribute(Name,Value);
END;
BEGIN
END.
}
}