[英]c# White space in XElement
I need to create XML request like this: 我需要这样创建XML请求:
<PosXML version="7.2.0">
<ReadCardRequest>
<Amount>10</Amount>
<CurrencyName>EUR</CurrencyName>
</ReadCardRequest>
</PosXML>
I have problem with PosXML line. 我对PosXML行有疑问。 It works only when to use simply PosXML but gets error when it is PosXML version="7.2.0" 它仅在仅使用PosXML时有效,而在PosXML version =“ 7.2.0”时出错。
My code right now: 我现在的代码:
XDocument doc = new XDocument(new XElement("PosXML",
new XElement("ReadCardRequest",
new XElement("Amount", summa.ToString()),
new XElement("CurrencyName", "EUR"))));
Any suggestions? 有什么建议么?
You can use an XAttribute for that: 您可以为此使用XAttribute:
XDocument doc = new XDocument(new XElement("PosXML",
new XElement("ReadCardRequest",
new XElement("Amount", "1"),
new XElement("CurrencyName", "EUR")),
new XAttribute("version","7.2.0")));
(As poke also pointed out) (正如戳也指出的那样)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.