我使用此代码从DataTable导出到XML文件:
dt1 = TNET2_POHeadService.TNET2_POHead_GetByPO_NoRaw(PO_No);
dt2 = TNET2_PODetailsService.TNET2_PODetails_GetByPO_NoRaw(PO_No);
ds.Tables.Add(dt1);
ds.Tables[0].TableName = "TNET2_POHead";
ds.Tables.Add(dt2);
ds.Tables[1].TableName = "TNET2_PODetails";
saveFileDialog1.ShowDialog();
ds.WriteXml(saveFileDialog1.FileName);
一切正常但是:
<ContractNo>P1717-198905-003(01)</ContractNo>
<KP_No xml:space="preserve"> </KP_No>
<SettlementRoute1>TENTAC SUZHOU</SettlementRoute1>
KP_No标记为空白值。我想删除xml:space =&#34;保留&#34; XML导出文件。怎么做?
答案 0 :(得分:4)
<?php $successful_students_items = get_post_meta( get_the_id(), 'successful_students_block_box', true );
if( !empty( $successful_students_items ) ) {
foreach( $successful_students_items as $successful_students_item ) { ?>
<div class="ipd-je-8 ipd-rz-8 ipd-pv-12 ipd-ke-24">
<div class="rjeudirnskxzi nnu">
<div class="h1ge6swchqzj6de">
<div class="h1ge6swchqzj6de_cvz">
<figure class="o309iruhgtybgyu5">
<blockquote><?php echo $successful_students_item['successful_students_block_testimonial']; ?>
<div class="ingi3h38d8jj4"></div>
</blockquote>
<img alt="" src="<?php echo $successful_students_item['successful_students_block_image']; ?>"/>
<div class="ewr4i9548jfdeuthie">
<h5><?php echo $successful_students_item['successful_students_block_name_lastname']; ?>
<span>
<br>
<?php echo $successful_students_item['successful_students_block_position']; ?>
</span>
</h5>
</div>
</figure>
</div>
</div>
</div>
</div>
<?php }
} ?>
命名空间中的 XDocument 类允许使用LINQ轻松管理和操作XML。
请参阅下面的示例,从XML文件的 KP_No 元素中删除System.Xml.Linq
属性:
xml:space="preserve"
请注意,您的XML没有根元素。在XML中定义一个是一个好习惯。
上面的代码段后面的结果:
XDocument doc = XDocument.Load("XMLFile1.xml"); // or XDocument.Load(myStream) ...
Func<XAttribute, bool> preserveAttrFunc = atr => atr.Name.LocalName == "space" && atr.Value == "preserve";
XElement kp_no = doc.Descendants("KP_No").FirstOrDefault(kp => kp.HasAttributes && kp.Attributes().Any(preserveAttrFunc));
if(kp_no != null)
kp_no.Attributes().FirstOrDefault(preserveAttrFunc).Remove();
// doc.Save(filename) ...