Cảm ơn gợi ý trước đó để sử dụng "XMLWriter", mọi lúc nó tạo tệp xml mới, vì vậy tôi đã sử dụng xmldoc để tải tệp xml rồi thêm vào tệp đó, đây là mã của tôi nhưng nó ném ngoại lệ nói " Tài liệu này đã có nút 'DocumentElement'. "Nối xml file bằng cách sử dụng xmlwriter
//Append to xml file
XmlDocument doc = new XmlDocument();
doc.Load(@"c:\\test.xml");
using (XmlWriter xmlWrite = doc.CreateNavigator().AppendChild())
{
xmlWrite.WriteStartElement("image name=",Name);
xmlWrite.WriteElementString("width", widthValue[1]);
xmlWrite.WriteElementString("Height", heightValue[1]);
xmlWrite.WriteElementString("file-size", FileSizeValue[1]);
xmlWrite.WriteElementString("file-format", FileFormatValue[1]);
xmlWrite.WriteElementString("resolution", ResolutionValue[1]);
xmlWrite.Close();
}
đây là test.xml mẫu của tôi
<job-metadata>
<slug>730s_Sales/CupWinner_0111</slug>
<locations>Africa</locations>
<primary-location>Africa</primary-location>
<reporter>Leigh Sales</reporter>
<genre>Current</genre>
<copyright>CBS</copyright>
<autopublish>true</autopublish>
</job-metadata>
Am cố gắng thêm trong xml như dưới đây
<job-metadata>
<slug>730s_Sales/CupWinner_0111</slug>
<locations>Africa</locations>
<primary-location>Africa</primary-location>
<reporter>Leigh Sales</reporter>
<genre>Current</genre>
<copyright>CBS</copyright>
<autopublish>true</autopublish>
- <image name="557684_20111101-730s_SalesCupWinner_0111_80x60.jpg">
<width>80</width>
<height>60</height>
<file-size>7045</file-size>
<file-format>JPEG Baseline</file-format>
<resolution>72</resolution>
<custom-name>newsthumbnail</custom-name>
</image>
</job-metadata>
Cảm ơn trước
là nó hữu ích không? ................. –
Tuyệt đối, cảm ơn rất nhiều ví dụ, tôi chưa sửa đổi, tôi sẽ sao t viết một cái bây giờ. tôi sẽ đăng mã trở lại đây. Cảm ơn một lần nữa – Usher