Asked by:
Reading multiple sentences CDATA from xml node

-
Hello
I need help in reading multiple sentences in xml Node
for example i have this xml
<description><![CDATA[Create level 1 diagrams.
Breakdown DFDs into lower level diagrams.
Design DFDs into 3rd normal form.
]]></description>
now i want to read the data inside the <description> but i want to loop inside the node and each sentance ending with "." be as one line so the output be like this
output
1- Create level 1 diagrams.
2- Breakdown DFDs into lower level diagrams.
3- Design DFDs into 3rd normal form.
i did this so far what is missing so i can read the data as i outlined
foreach (var xobjective in xsession.Descendants("description"))
{
string objName = xobjective.Value;
string objVerb = Regex.Match(xobjective.Value, @"^(\w+\b.*?){1}").ToString();
LSDEObjective objective = new LSDEObjective(objName, objVerb);
session.addObjective(objective);
}
Question
All replies
-
Can't you simply split:
string xml = @"<description><![CDATA[Create level 1 diagrams. Breakdown DFDs into lower level diagrams. Design DFDs into 3rd normal form. ]]></description>"; XDocument doc = XDocument.Parse(xml); foreach (XElement desc in doc.Descendants("description")) { foreach (string line in desc.Value.Split('\n', '\r').Where(s => s.Trim() != "")) { Console.WriteLine("\"{0}\"", line); } } }
MVP (XML, Data Platform Development) 2005/04 - 2013/03 My blog
-
Thank you for your help it did work
i want to add this code that can specify the first word for each line
string objVerb = Regex.Match(xobjective.Value, @"^(\w+\b.*?){1}").ToString();
so when it outputs the sentences it looks like that
1-Create level 1 diagrams. verb: Create
2-Breakdown DFDs into lower level diagrams. verb:Breakdown
3-Design DFDs into 3rd normal form. verb:Design -
-
Does
string xml = @"<description><![CDATA[Create level 1 diagrams. Breakdown DFDs into lower level diagrams. Design DFDs into 3rd normal form. ]]></description>"; XDocument doc = XDocument.Parse(xml); foreach (XElement desc in doc.Descendants("description")) { foreach (string line in desc.Value.Split('\n', '\r').Where(s => s.Trim() != "").Select((s, p) => (p + 1) + "-" + s)) { Console.WriteLine("\"{0}\"", line); } } }
output what you want?
MVP (XML, Data Platform Development) 2005/04 - 2013/03 My blog