AL icon indicating copy to clipboard operation
AL copied to clipboard

xmlAttributeCollection

Open abouraoui opened this issue 7 years ago • 7 comments

Hi,

trying to get the attribute list from an xml file, I use xmlAttributecollection but cannot get the list of attributes.

here is my code: xmlNode: XmlNode; xmlAttributeList: XmlAttributeCollection; xmlAttribute: XmlAttribute;

xmlNodeList := pTableDATA.GetChildNodes(); (pTableDATA is an xmlFile as listed below)

                for i := 1 to xmlNodeList.Count do begin

                    xmlNodeList.Get(i, xmlNode);
                    xmlElement2 := xmlelement.create('Attributes');
                    xmlElement2.add(xmlNode);
                    xmlAttributeList := xmlElement2.Attributes();
                    
                    Message('xmlAttributeList.Count ' + Format(xmlAttributeList.Count));

the message shows value of 0, here is the xml file:

abouraoui avatar May 27 '19 18:05 abouraoui

abouraoui avatar May 27 '19 18:05 abouraoui

abouraoui avatar May 27 '19 18:05 abouraoui

image

abouraoui avatar May 27 '19 18:05 abouraoui

I have the same issue, once I do VarXmlNodeList.Get(0, VarXmlNode) I get an error message with "0".

angela2389 avatar Jun 11 '19 13:06 angela2389

@thloke ,why is this marked as a question? It seems a bug to me...

angela2389 avatar Jun 18 '19 13:06 angela2389

@angela2389 The Get() method on XmlNodeList is 1-based like most of AL. It is also stated in the documentation https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/xmlnodelist/xmlnodelist-get-method.

The error-message is lacking and will be updated.

esbenk avatar Jul 07 '20 13:07 esbenk

@abouraoui The code sample does exactly what it should.

xmlElement2 := xmlelement.create('Attributes');

Creates a new element named 'Attribute' e.g.

xmlElement2.add(xmlNode)

Add the content of xmlNode to the newly created element e.g. Content from XmlNode

xmlAttributeList := xmlElement2.Attributes();

Gets a list of attributes on the element, which is empty and hence have Count = 0.

esbenk avatar Jul 07 '20 13:07 esbenk