![](/img/trans.png)
[英]In C#, how can I use Regex.Replace to add leading zeroes (if possible)?
[英]I have an xml string and I want to to use regex.Replace in C# to add 2 more tags to the exixtsing string. How can i Do that?
我有這個xml字符串
<TaxType ident="XXX"><TaxMethod billingBasis="Net" billingUOM="Dollars-Gallon" />
<TaxRate>1.0</TaxRate><TaxAmount>10</TaxAmount><TaxDeferred yesOrNo="yes" />
<TaxExempt yesOrNo="No" />
</TaxType>
至
<TaxType ident="XXX"><TaxMethod billingBasis="Net" billingUOM="Dollars-Gallon" />
<TaxRate>1.0</TaxRate><TaxAmount>10</TaxAmount><TaxDeferred yesOrNo="yes" />
<TaxDeferredInvoiceNumber>12345</TaxDeferredInvoiceNumber>
<TaxDeferredPaymentDueDate>2012-01-23</TaxDeferredPaymentDueDate>
<TaxExempt yesOrNo="No" />
</TaxType>
即添加兩個額外的標簽來存在的XML字符串。 如何在C#中使用regex.Replace做到這一點? 有人可以建議嗎?
使用正則表達式可以工作,但是我建議將XML加載到XMLDocument中並修改該特定節點。 它更容易編寫代碼,而且下一個研究它的人也更容易閱讀。
盡管正則表達式是功能強大的工具,但我認為它不是完成此工作的正確工具。
請參閱: 使用XMLdocument添加節點
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.