-2

我正在将 excel 工作表转换为 xml 格式。我面临的问题是我有很多没有任何数据的字段。对于那些,我得到一个像这样的空白标签:

<event-name />

我想要的是这个标签应该是这种格式:

<event-name></event-name>




string Title                = dsPushTable.Rows[i]["title"].ToString();
                string Shortdescription     = dsPushTable.Rows[i]["short-description"].ToString();
                string sampleimageshref1    = dsPushTable.Rows[i]["sampleimageshref"].ToString();
                string sampleimageshref2    = dsPushTable.Rows[i]["sampleimageshref1"].ToString();
                string variantshref1        = dsPushTable.Rows[i]["variantshref1"].ToString();
                string variantshref2        = dsPushTable.Rows[i]["variantshref2"].ToString();
                string start                = dsPushTable.Rows[i]["life-cyclestart"].ToString();
                string end                  = dsPushTable.Rows[i]["life-cycleend"].ToString();
                string contentcpid          = dsPushTable.Rows[i]["content-cp-id"].ToString();
                string Keyw                 = dsPushTable.Rows[i]["keywords"].ToString();
                string categoriesref1       = dsPushTable.Rows[i]["categoriesref1"].ToString();
                string categoriesref2       = dsPushTable.Rows[i]["categoriesref2"].ToString();
                string Moviename = dsPushTable.Rows[i]["movie-name"].ToString();
                string actorname = dsPushTable.Rows[i]["actor-name"].ToString();
                string lyricist = dsPushTable.Rows[i]["lyricist"].ToString();
                string singername = dsPushTable.Rows[i]["singer-name"].ToString();
                string Label = dsPushTable.Rows[i]["label"].ToString();











                Directory.CreateDirectory(xmlFilePath);
                XmlTextWriter xmlWriter = new XmlTextWriter(xmlFilePath + "/" + Title + ".xml", Encoding.Unicode);
                xmlWriter.Formatting = Formatting.Indented;

                xmlWriter.WriteStartElement("MP3Tone"); //Root Element

                xmlWriter.WriteStartElement("title"); //Attribute "partnerProductId"
                xmlWriter.WriteString(Title); //Attribute Value 
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("short-description"); //Attribute "partnerProductId"
                xmlWriter.WriteString(Shortdescription); //Attribute Value 
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("provider"); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("ref"); //Attribute "partnerProductId"
                xmlWriter.WriteString("/data/cp_ref/techzone.ContentProvider"); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("sample-images"); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("href"); //Attribute "partnerProductId"
                xmlWriter.WriteString(sampleimageshref1); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("transcodable"); //Attribute "partnerProductId"
                xmlWriter.WriteString("False"); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteEndElement(); //offering Element


                xmlWriter.WriteStartElement("sample-images"); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("href"); //Attribute "partnerProductId"
                xmlWriter.WriteString(sampleimageshref2); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("transcodable"); //Attribute "partnerProductId"
                xmlWriter.WriteString("False"); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("variants"); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("href"); //Attribute "partnerProductId"
                xmlWriter.WriteString(variantshref1); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("transcodable"); //Attribute "partnerProductId"
                xmlWriter.WriteString("False"); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteEndElement(); //offering Element


                xmlWriter.WriteStartElement("variants"); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("href"); //Attribute "partnerProductId"
                xmlWriter.WriteString(variantshref2); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("transcodable"); //Attribute "partnerProductId"
                xmlWriter.WriteString("False"); //Attribute Value 
                xmlWriter.WriteEndElement();  //Attribute "partnerProductId"
                xmlWriter.WriteEndElement();  //offering Element

                xmlWriter.WriteStartElement("status"); //Attribute "partnerProductId"
                xmlWriter.WriteString("Submit"); //Attribute Value 
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("life-cycle"); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("start"); //Attribute "partnerProductId"
                xmlWriter.WriteString(start); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("end"); //Attribute "partnerProductId"
                xmlWriter.WriteString(end); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("content-cp-id"); //Attribute "partnerProductId"
                xmlWriter.WriteString(contentcpid); //Attribute Value 
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("keywords"); //Attribute "partnerProductId"
                xmlWriter.WriteString(Keyw); //Attribute Value 
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("categories"); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("ref"); //Attribute "partnerProductId"
                xmlWriter.WriteString(categoriesref1); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteEndElement(); //offering Element


                xmlWriter.WriteStartElement("categories"); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("ref"); //Attribute "partnerProductId"
                xmlWriter.WriteString(categoriesref2); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("bearer-type"); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("bearer-2g"); //Attribute "partnerProductId"
                xmlWriter.WriteString("True"); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("bearer-2.5g"); //Attribute "partnerProductId"
                xmlWriter.WriteString("True"); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("bearer-3g"); //Attribute "partnerProductId"
                xmlWriter.WriteString("True"); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("charge-code"); //Attribute "partnerProductId"
                xmlWriter.WriteString("CHC01500"); //Attribute Value 
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("right-owner"); //Attribute "partnerProductId"
                xmlWriter.WriteString("/data/rights123.RightsOwner"); //Attribute Value 
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("ingestion-timestamp"); //Attribute "partnerProductId"
                xmlWriter.WriteString(start); //Attribute Value 
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("delivery-methods"); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("wap"); //Attribute "partnerProductId"
                xmlWriter.WriteString("True"); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("web"); //Attribute "partnerProductId"
                xmlWriter.WriteString(""); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteStartElement("sms"); //Attribute "partnerProductId"
                xmlWriter.WriteString(""); //Attribute Value 
                xmlWriter.WriteEndElement(); //Attribute "partnerProductId"
                xmlWriter.WriteEndElement(); //offering Element

xmlWriter.WriteStartElement("movie-name"); //Attribute "partnerProductId"
                xmlWriter.WriteString(Moviename); //Attribute Value 

                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("actor-name"); //Attribute "partnerProductId"
                xmlWriter.WriteString(actorname); //Attribute Value 

                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("lyricist"); //Attribute "partnerProductId"
                xmlWriter.WriteString(lyricist); //Attribute Value 

                xmlWriter.WriteEndElement(); //offering Element


                xmlWriter.WriteStartElement("singer-name"); //Attribute "partnerProductId"
                xmlWriter.WriteString(singername); //Attribute Value 

                xmlWriter.WriteEndElement(); //offering Element


                xmlWriter.WriteStartElement("event-name"); //Attribute "partnerProductId"
                xmlWriter.WriteString(""); //Attribute Value 
                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("composer-Name"); //Attribute "partnerProductId"
                xmlWriter.WriteString(""); //Attribute Value 
                xmlWriter.WriteEndElement(); //offering Element



                xmlWriter.WriteStartElement("isrc-code"); //Attribute "partnerProductId"
                xmlWriter.WriteString(""); //Attribute Value 
                xmlWriter.WriteEndElement(); //offering Element


                xmlWriter.WriteStartElement("all-region"); //Attribute "partnerProductId"
                xmlWriter.WriteString("True"); //Attribute Value 

                xmlWriter.WriteEndElement(); //offering Element


                xmlWriter.WriteStartElement("label"); //Attribute "partnerProductId"
                xmlWriter.WriteString(Label); //Attribute Value 

                xmlWriter.WriteEndElement(); //offering Element

                xmlWriter.WriteStartElement("approved-timestamp"); //Attribute "partnerProductId"
                xmlWriter.WriteString(""); //Attribute Value 
                xmlWriter.WriteEndElement(); //offering Element


                xmlWriter.WriteEndElement();//End artists Element



                xmlWriter.Flush();
                xmlWriter.Close();
4

1 回答 1

2

使用WriteFullEndElement而不是WriteEndElement.

于 2013-04-11T07:12:49.440 回答