I have a XML like
<XYZ>front0
and</XYZ>
when I save text in xml it save exactly like whatever I type..but when I fetch from XML then it display in one line.. what is the problem?? any suggestion plz
UPDATE
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;
..
by innerText I fetch XML value .. its like n.ChildNodes[0].InnerText; "front0 and \\r\\n\\r\\nsaid can " string
n.ChildNodes[0].InnerText; "front0 and \\r\\n\\r\\nsaid can " string
but when I display it in div tag it shows in single line
UPDATE
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;
}
How do you read your XML? What do you mean by "fetch XML"?
There are many ways in C# to read XML contents of a file.
Please, provide a code snippet for fetching your XML file.
Here is my code snippet which loads XML data from a string (it is correct due to assuming that your file is writing correctly). It properly reads multiline XML element to a string.
Update: Oh, now I get it. I met the same problem when I was learning PHP. It was totally driving me crazy.
Then, I have found an answer: the text is actually displaying correctly. However, HTML doesn't output line breaks .
It means that:
You have XML:
<value>Hi
I am a multiline
value</value>
It is properly read to a string and outputed to an HTML like this:
<div>
Hi
I am a multiline
value
</div>
However, in browser you will see a single line. Here is a JSFiddle: http://jsfiddle.net/s9d36a8n/
You can ensure if I am right by looking at the source code (Ctrl + U in most browsers).
If you want the data to be displayed on several lines, you need to place HTML line break <br/>
in the end of every line like this:
<div>
Hi<br/>
I am a multline<br/>
value
</div>
You can achieve this by executing
htmlWithBrs = cont.Replace(Environment.NewLine, "<br/>");
You will get something like this: http://jsfiddle.net/5vtk8ovk/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.