Hi,
Hope you all are doing well.
I'm trying to build following xml in AL
<?xml version="1.0" encoding="UTF-8" standalone=""?>
<Invoice
xmlns:cac="is:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<ext:UBLExtensions>
<ext:UBLExtension>urn:oas
<ext:ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ext:ExtensionURI>
</ext:UBLExtension>
</ext:UBLExtensions>
</Invoice>
I wrote following piece of code to get the xml given above.
local procedure BuildXml(): Text
var
XmlDoc: XmlDocument;
XmlDec: XmlDeclaration;
InvoiceElement: XmlElement;
UBLExtensionsElement: XmlElement;
UBLExtensionElement: XmlElement;
ExtensionURIElement: XmlElement;
NameSpaceUrl: Text;
XmlIntoText: Text;
begin
XmlDoc := XmlDocument.Create();
XmlDec := XmlDeclaration.Create('1.0', 'UTF-8', '');
XmlDoc.SetDeclaration(XmlDec);
NameSpaceUrl := 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2';
InvoiceElement := XmlElement.Create('Invoice', NameSpaceUrl);
InvoiceElement.Add(XmlAttribute.CreateNamespaceDeclaration('cac', 'is:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'));
InvoiceElement.Add(XmlAttribute.CreateNamespaceDeclaration('cbc', 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2'));
InvoiceElement.Add(XmlAttribute.CreateNamespaceDeclaration('ext', 'urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2'));
UBLExtensionsElement := XmlElement.Create('UBLExtensions', NameSpaceUrl);
UBLExtensionElement := XmlElement.Create('UBLExtension', NameSpaceUrl, 'urn:oas');
ExtensionURIElement := XmlElement.Create('ExtensionURI', NameSpaceUrl);
ExtensionURIElement.Add(XmlText.Create('urn:oasis:names:specification:ubl:dsig:enveloped:xades'));
UBLExtensionElement.Add(ExtensionURIElement);
UBLExtensionsElement.Add(UBLExtensionElement);
InvoiceElement.Add(UBLExtensionsElement);
XmlDoc.Add(InvoiceElement);
XmlDoc.WriteTo(XmlIntoText);
exit(XmlIntoText);
end
By running the code given above, I'm getting the following xml output.
<?xml version="1.0" encoding="UTF-8" standalone=""?>
<Invoice
xmlns:cac="is:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<UBLExtensions>
<UBLExtension>urn:oas
<ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ExtensionURI>
</UBLExtension>
</UBLExtensions>
</Invoice>
As we can see, the prefix 'ext' is missing with each child node. Can anyone please tell me how can I add the ext prefix with an XmlNode's or XmlElement's Name?
Answers will be highly appreciated.