Tôi đang tìm trên Internet cách giữ vận chuyển trở lại từ dữ liệu XML nhưng tôi không thể tìm thấy câu trả lời, vì vậy tôi ở đây :)Làm thế nào giữ vận chuyển trở lại từ phân tích cú pháp XML
Mục tiêu là viết một tệp nội dung của dữ liệu XML. Vì vậy, nếu giá trị của nút chứa một số dữ liệu "\ r \ n", thì phần mềm cần phải ghi chúng vào tệp để tạo dòng mới, nhưng nó không viết, ngay cả với không gian: bảo toàn.
Đây là lớp học thử nghiệm của tôi:
XElement xRootNode = new XElement("DOCS");
XElement xData = null;
//XNamespace ns = XNamespace.Xml;
//XAttribute spacePreserve = new XAttribute(ns+"space", "preserve");
//xRootNode.Add(spacePreserve);
xData = new XElement("DOC");
xData.Add(new XAttribute("FILENAME", "c:\\titi\\prout.txt"));
xData.Add(new XAttribute("MODE", "APPEND"));
xData.Add("Hi my name is Baptiste\r\nI'm a lazy boy");
xRootNode.Add(xData);
bool result = Tools.writeToFile(xRootNode.ToString());
Và đây là quá trình lớp học của tôi:
try
{
XElement xRootNode = XElement.Parse(xmlInputFiles);
String filename = xRootNode.Element(xNodeDoc).Attribute(xAttributeFilename).Value.ToString();
Boolean mode = false;
try
{
mode = xRootNode.Element(xNodeDoc).Attribute(xWriteMode).Value.ToString().ToUpper().Equals(xWriteModeAppend);
}
catch (Exception e)
{
mode = false;
}
String value = xRootNode.Element(xNodeDoc).Value;
StreamWriter destFile = new StreamWriter(filename, mode, System.Text.Encoding.Unicode);
destFile.Write(value);
destFile.Close();
return true;
}
catch (Exception e)
{
return false;
}
Có ai có một ý tưởng?
bạn nên đặt dữ liệu đó vào vì XML sẽ cố gắng để phân tích chúng. – Burimi
Làm thế nào để làm điều đó? – BaptX
Công việc của một trình phân tích cú pháp xml để chuẩn hóa các nguồn cấp dữ liệu dòng khác nhau thành \ n. Vì vậy, đây là hành vi mặc định. – Totonga