Reputation: 5
i need to Write Attribute String in Write Element String if Write Element String contains string values i'am trying this code but it doesn't work
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();
if i have a string value in CLAFCNO this is the result do i need
<W-TIBCPTR>
<W-TIBCPTRs>
<TYPTRT>FDR2 R</TYPTRT>
<CLAFCNO verifier="NO">5D1</CLAFCNO>
<NUMCLI>0067781</NUMCLI>
<TYPACT>D</TYPACT>
</W-TIBCPTRs>
</W-TIBCPTR>
if i have a number i need this result
<W-TIBCPTR>
<W-TIBCPTRs>
<TYPTRT>FDR2 R</TYPTRT>
<CLAFCNO>5D1</CLAFCNO>
<NUMCLI>0067781</NUMCLI>
<TYPACT>D</TYPACT>
</W-TIBCPTRs>
</W-TIBCPTR>
Upvotes: 0
Views: 1276
Reputation: 133950
I think you're looking for WriteString:
w.WriteStartElement("CLAFCNO");
w.WriteAttributeString("verifier", "Non");
w.WriteString(CLAFCNO);
w.WriteEndElement();
Upvotes: 4