我必须根据用户输入动态创建一个 XML 文件。
这是我的想法,但我遇到了两个问题。
- 如果存在相同元素的集合(MaxOccurs = 10)
(例如,如果用户输入了 4 个帐户,那么我的代码应该如何)
- 如果有选择的话。根据所选元素,子元素应该发生变化。
有人请帮助我。
提前致谢
BB
我的代码:
XElement req =
new XElement("order",
new XElement("client",
new XAttribute("id", clientId),
new XElement("quoteback",
new XAttribute ("name",quotebackname)
)
),
new XElement("accounting",
new XElement("account"),
new XElement("special_billing_id")
),
new XElement("products",
new XElement(
**productChoiceType**,
***** HERE THE ELEMENTS WILL CHAGE BASED ON **productChoiceType**
)
)
)
);
LINQ 可以在处理以下事情时派上用场:
XElement req =
new XElement("order",
new XElement("client",
new XAttribute("id",clientId),
new XElement("quoteback", new XAttribute ("name",quotebackname))
),
new XElement("accounting",
new XElement("account"),
new XElement("special_billing_id")
),
new XElement("products",
new XElement(productChoices.Single(pc => pc.ChoiceType == choiceType).Name,
from p in products
where p.ChoiceType == choiceType
select new XElement(p.Name)
)
)
);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)