var XmlAttrCol: XmlAttributeCollection; begin XmlAttrCol.Set('attr1', 'value1'); XmlAttrCol.Set('attr2', 'value2'); XmlAttrCol.Set('attr3', 'value3'); XmlAttrCol.Set('attr4', 'value4'); end;I am getting an error:
But there is no such method to initialize XmlAttributeCollection...Microsoft.Dynamics.Nav.Runtime.NavXmlAttributeCollection was not initialized.
var XmlAttrCol: XmlAttributeCollection; XmlElem: XmlElement; begin XmlAttrCol := XmlElem.Attributes(); XmlAttrCol.Set('attr1', 'value1'); XmlAttrCol.Set('attr2', 'value2'); XmlAttrCol.Set('attr3', 'value3'); XmlAttrCol.Set('attr4', 'value4'); end;but with the same error...
var XmlAttrCol: XmlAttributeCollection; XmlElem: XmlElement; begin XmlElem := XmlElement.Create('sampleElement'); XmlAttrCol := XmlElem.Attributes(); XmlAttrCol.Set('attr1', 'value1'); XmlAttrCol.Set('attr2', 'value2'); XmlAttrCol.Set('attr3', 'value3'); XmlAttrCol.Set('attr4', 'value4'); end;
Answers
The thing is, that you have to create the XmlElement first, then the second variant works. so...
...works fine.