如何折叠空的 xml 标签? [英] How do I collapse empty xml tags?

查看:34
本文介绍了如何折叠空的 xml 标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这样的 XML:

I'm getting XML like this:

<代码><物品><Row attr1="val"></Row><Row attr1="val2"></Row></物品>

正如您所知,这是有效的 XML,但我正在使用的另一个库已被破坏,它只接受这种格式的 XML:

This is valid XML, as you know, but another library I'm using is busted and it will only accept XML in this format:

<代码><物品><Row attr1="val"/><Row attr1="val2"/></项目>

我已经将 XML 读入 XmlDocuments、操作它们并使用 XmlWriter() 重写它们,对我来说折叠"这些空标签的最简单(也是最有效)的方法是什么?

I'm already reading the XML into XmlDocuments, manipulating them, and rewriting them using an XmlWriter(), what's the easiest (and most efficient) way for me to "collapse" these empty tags?

推荐答案

设置 IsEmpty 要折叠为 true 的每个 XmlElement 的属性.

Set the IsEmpty property of each XmlElement you want to collapse to true.

这篇关于如何折叠空的 xml 标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆