简体   繁体   English

使用Delphi中的IXMLDOMDOCUMENT删除xsi:nil attibute

[英]Remove xsi:nil attibute using IXMLDOMDOCUMENT in Delphi

I have an xml document that contains many xml nodes. 我有一个包含许多xml节点的xml文档。 The document has xsi:nil="true" attributes. 该文档具有xsi:nil="true"属性。 If I set values on these nodes, the nil attribute remains and it becomes invalid against my xsd. 如果我在这些节点上设置值,则nil属性仍然存在,并且对我的xsd无效。

Question: 题:

How do I remove the xsi:nil attributes using Delphi 2006 code with the MSXML2_TLB? 如何使用带有MSXML2_TLB的Delphi 2006代码删除xsi:nil属性?

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. 在节点本身上调用IXmlDomElement.removeAttribute ,而不是属性集合。 Any IXmlDomNode object that represents an element should implement IXmlDomElement as well, so type-cast the node: 表示元素的任何IXmlDomNode对象也应该实现IXmlDomElement ,因此对节点进行类型转换:

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

If you're using the XmlIntf unit instead of the Microsoft DOM, then call IXmlNode.SetAttributeNS . 如果您使用的是XmlIntf单元而不是Microsoft DOM,请调用IXmlNode.SetAttributeNS Pass Null as the value and the attribute will be removed: 传递Null作为值,该属性将被删除:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM