如果写元素字符串包含字符串值,我需要在写元素字符串中写入属性字符串--我正在尝试这段代码,但它不起作用
w.WriteStartElement("W-TIBCPTRs");
w.WriteElementString("TYPTRT", TYPTRT);
if (Regex.IsMatch(CLAFCNO, @"^\d+$"))
{
w.WriteElementString("CLAFCNO", CLAFCNO);
}
else
{
w.WriteElementString("CLAFCNO", CLAFCNO);
w.WriteAttributeString("verifier", "Non");
}
w.WriteElementString("NUMCLI", NUMCLI);
w.WriteElementString("TYPACT", TYPACT);
w.WriteEndElement();如果我在CLAFCNO中有一个字符串值,这就是我需要的结果
<W-TIBCPTR>
<W-TIBCPTRs>
<TYPTRT>FDR2 R</TYPTRT>
<CLAFCNO verifier="NO">5D1</CLAFCNO>
<NUMCLI>0067781</NUMCLI>
<TYPACT>D</TYPACT>
</W-TIBCPTRs>
</W-TIBCPTR> 如果我有一个号码,我需要这个结果
<W-TIBCPTR>
<W-TIBCPTRs>
<TYPTRT>FDR2 R</TYPTRT>
<CLAFCNO>5D1</CLAFCNO>
<NUMCLI>0067781</NUMCLI>
<TYPACT>D</TYPACT>
</W-TIBCPTRs>
</W-TIBCPTR> 发布于 2014-06-14 04:34:50
我想你是在找WriteString
w.WriteStartElement("CLAFCNO");
w.WriteAttributeString("verifier", "Non");
w.WriteString(CLAFCNO);
w.WriteEndElement();https://stackoverflow.com/questions/24216368
复制相似问题