[XML]优雅的创作和追加 [英] [XML] Graceful creation and appending

查看:55
本文介绍了[XML]优雅的创作和追加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


这是我到目前为止所做的。我更喜欢你在第一个条件下创造的方式。但是,我不知道如何以类似的方式添加新元素。

有没有办法减少第二个条件下的代码量?


所需输出:


代码:

Hello guys,

here is what I did so far. I prefer the way you create in the first condition. however, i do not know how to append new elements in the similar way.
is there a way to reduce amount of code in 2nd condition?

Desired output:

Code:


<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>

- < Definitions>

- <定义>

<缩写> a1< /缩略语>

< Name> n1< / Name>

- < Value>

< A> 1< / A>

< B> 2< / B>

< Alpha> 3< / Alpha>

< Beta> 4< / Beta>

< / Value>

< /定义>

- <定义>

<缩写> ; TEST2< /缩写>

< Name> test22< / Name>

- < Value>

< A> 551< / A>

< B> 23< / B>

< Alpha> 0.12< / Alpha>

< Beta> -95.21< / Beta>

< / Value>

< / Definition>

< / Definitions>
<?xml version="1.0" encoding="utf-8" ?>
- <Definitions>
- <Definition>
<Acronym>a1</Acronym>
<Name>n1</Name>
- <Value>
<A>1</A>
<B>2</B>
<Alpha>3</Alpha>
<Beta>4</Beta>
</Value>
</Definition>
- <Definition>
<Acronym>test2</Acronym>
<Name>test22</Name>
- <Value>
<A>551</A>
<B>23</B>
<Alpha>0.12</Alpha>
<Beta>-95.21</Beta>
</Value>
</Definition>
</Definitions>

展开 | 选择 < span class =codeDivider> | Wrap | 行号

推荐答案

为什么不创建一个打包所有重复代码的方法到了吗?提供适当的参数并返回一个XmlNode?

您可以在更多地方执行此操作...在您发现自己复制了大量代码的任何地方,它可能是一个创建一个新方法的好主意。
Why not create a method that packages up all that duplicate code you''ve got there? Supply the appropriate parameters and return an XmlNode?

You can do this in more places as well... anywhere you find yourself duplicating a good bit of code, it''s probably a good idea to create a new method.


@GaryTexmo,

感谢队友。好主意......完全忘了它。

快速原型,现在还没有考虑到一切。您怎么看?

@GaryTexmo,
thanks mate. good idea...totally forgot about it.
quick "prototype", haven''t taken into account everything for now. what do you think?

展开 | 选择 | Wrap | 行号


我觉得这很好:)还有一件事需要建议...而不是这些行:

I think that''s fine :) One other thing to suggest... instead of these lines:

展开 | 选择 | Wrap | 行号


这篇关于[XML]优雅的创作和追加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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