【发布时间】:2015-08-22 11:52:28
【问题描述】:
我有一个类似的 XML
<XYZ>front0
and</XYZ>
当我在 xml 中保存文本时,它保存的内容与我键入的内容完全相同。但是当我从 XML 中获取时,它会显示在一行中。 问题是什么??有什么建议吗
更新
XmlDocument xd = new XmlDocument();
string LastModifiedByTrans = "";
string date = "";
string LastModifiedByQaed = "";
string QAed_date = "";
try
{
foreach (var g in gp)
{
p.text = g.Text_xml.ToString();
// LOAD TEXT XML
xd.LoadXml(p.text);
XmlNodeList txt = xd.GetElementsByTagName("Texts");
for (int i = 0; i < txt.Count; i++)
{
XmlNode nd = txt.Item(i);
if (nd.HasChildNodes)
{
XmlNodeList cnd = nd.ChildNodes;
foreach (XmlNode n in cnd)
{
cont = n.ChildNodes[0].InnerText;
..
通过 innerText 我获取 XML 值..
就好像是
n.ChildNodes[0].InnerText; "front0 and \r\n\r\nsaid can " string
但是当我在 div 标签中显示它时,它显示为单行
更新
public List<Room> getText(decimal Trans_ID, decimal Job_ID, string GroupName, string path)
{
GroupData p = new GroupData();
Room newroom = new Room();
var room = new List<Room>();
XmlDocument xd = new XmlDocument();
string LastModifiedByTrans = "";
string date = "";
string LastModifiedByQaed = "";
string QAed_date = "";
try
{
var gp = (from Trans_Mast in r2ge.Transcription_Master where Trans_Mast.Transcription_Id == Trans_ID && Trans_Mast.Entity_Id == Job_ID select Trans_Mast).Distinct();
foreach (var g in gp)
{
p.text = g.Text_xml.ToString();
// LOAD TEXT XML
xd.LoadXml(p.text);
XmlNodeList txt = xd.GetElementsByTagName("Texts");
for (int i = 0; i < txt.Count; i++)
{
XmlNode nd = txt.Item(i);
if (nd.HasChildNodes)
{
XmlNodeList cnd = nd.ChildNodes;
if (role == "Transcriber")
{
foreach (XmlNode n in cnd)
{
if (GroupName == n.Attributes["group"].Value && n.Attributes["audio"].Value.Equals(path) && n.Attributes["role"].Value.Equals("QA"))
{
LastModifiedByQaed = n.Attributes["user"].Value;
if (((n.Attributes["datetime"]).Value).Length > 0)
{
QAed_date = Convert.ToDateTime(n.Attributes["datetime"].Value).ToString("yyyy/MM/dd HH:mm:ss");
}
else
QAed_date = "";
}
}
foreach (XmlNode n in cnd)
{
if (GroupName == n.Attributes["group"].Value && n.Attributes["audio"].Value.Equals(path))
{
string cont = "";
string contnt = "";
if ((n.ChildNodes).Count > 0)
{
cont = n.ChildNodes[0].InnerText;
contnt = cont.Replace(System.Environment.NewLine, "<br/>");
}
else
cont = "blank";
if (((n.Attributes["datetime"]).Value).Length > 0)
{
date = Convert.ToDateTime(n.Attributes["datetime"].Value).ToString("yyyy/MM/dd HH:mm:ss");
}
else
date = "";
Text text = new Text()
{
Content = cont,
LastModifiedOn = date,
LastModifiedBy = n.Attributes["user"].Value,
LastModifiedBy_Qaed = LastModifiedByQaed,
LastModifiedOn_Qaed = QAed_date
};
newroom.text.Add(text);
}
}
}
}
}
}
}
catch (Exception ex)
{
Console.Write("In fetch text data err", ex.Message);
throw ex;
}
room.Add(newroom);
return room;
}
【问题讨论】:
-
对不起,我没有指定..在 c# mvc @kupendra 中工作
-
然后查看Question
-
@kupendra 你错了。问题根本不在于换行。
-
@debin 您如何编写 XML 和读取 XML?能否请您提供代码示例?
标签: javascript c# xml