开发者

Remove xsi:nil attibute using IXMLDOMDOCUMENT in Delphi

开发者 https://www.devze.com 2023-01-31 10:01 出处:网络
I have an xml document that contains many xml nodes. The document has xsi:nil=\"t开发者_运维百科rue\" attributes. If I set values on these nodes, the nil attribute remains and it becomes invalid again

I have an xml document that contains many xml nodes. The document has xsi:nil="t开发者_运维百科rue" attributes. If I set values on these nodes, the nil attribute remains and it becomes invalid against my xsd.

Question:

How do I remove the xsi:nil attributes using Delphi 2006 code with the MSXML2_TLB?

I tried this:

xmlNode.attributes.removeNamedItem('xsi:nil');

It runs without an error, but does not remove the attribute.


Call IXmlDomElement.removeAttribute on the node itself, not the attribute collection. Any IXmlDomNode object that represents an element should implement IXmlDomElement as well, so type-cast the node:

OleCheck((xmlNode as IXmlDomElement).removeAttribute('xsi:nil'));

If you're using the XmlIntf unit instead of the Microsoft DOM, then call IXmlNode.SetAttributeNS. Pass Null as the value and the attribute will be removed:

xmlNode.SetAttributeNS('nil', 'xsi', Null);
0

精彩评论

暂无评论...
验证码 换一张
取 消