Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在WriteElementString中写入AttributeTestString_C#_Xml_Xmlwriter - Fatal编程技术网

C# 如何在WriteElementString中写入AttributeTestString

C# 如何在WriteElementString中写入AttributeTestString,c#,xml,xmlwriter,C#,Xml,Xmlwriter,我需要在Write元素字符串中写入属性字符串,如果Write元素字符串包含字符串值,我正在尝试这段代码,但它不起作用 w.WriteStartElement("W-TIBCPTRs"); w.WriteElementString("TYPTRT", TYPTRT); if (Regex.IsMatch(CLAFCNO, @"^\d+$")) { w.WriteElementString

我需要在Write元素字符串中写入属性字符串,如果Write元素字符串包含字符串值,我正在尝试这段代码,但它不起作用

        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> 

FDR
5D1
0067781
D
如果我有一个数字,我需要这个结果

<W-TIBCPTR>
  <W-TIBCPTRs>
    <TYPTRT>FDR2 R</TYPTRT>
    <CLAFCNO>5D1</CLAFCNO>
    <NUMCLI>0067781</NUMCLI>
    <TYPACT>D</TYPACT>

  </W-TIBCPTRs>
</W-TIBCPTR>  

FDR
5D1
0067781
D

我想您正在寻找:


我想你在寻找:


您试图生成的XML是什么?如果CLAFCNO中有一个字符串值,这是结果我需要FDR2 R 5D1 0067781 D吗?您试图生成的XML是什么?如果CLAFCNO中有一个字符串值,这是结果我需要FDR2 R 5D1 0067781 D吗
w.WriteStartElement("CLAFCNO");
w.WriteAttributeString("verifier", "Non");
w.WriteString(CLAFCNO);
w.WriteEndElement();