I have encountered a following problem. I have an XML document with a following content:
<Field>The list here:[LIST][*][B]Bold item 1[/B] - Item text, then linebreak[BR][/BR][B]Bold subitem[/B] even more text[BR][/BR][*][B]Bold item 2[/B] Item text and so one[/LIST]</Field>
I would need to replace the BB Tags with XML Tags, to get something like that:
<Field>The list here:<BB_LIST>
<BB_LI/>
<BB_B>Bold item 1</BB_B> - Item text, then linebreak<BB_BR/>
<BB_B>Bold subitem</BB_B> even more text<BB_BR/>
<BB_LI/>
<BB_B>Bold item 2</BB_B> Item text and so one</BB_LIST>
</Field>
I am using XDocument to go through XML elements in my document, and Codekicker BB Code parser (http://ift.tt/1yvj475).
The problem I have is that if I go through that element by element, the BB tags are escaped in the XML document (& lt; instead of < etc).
I tried also reading the XML document as text, line by line, but this way it's very easy to corrupt the XML with improper nesting of BB tags.
I don't even think I really need the BB parser, I just need to replace three types of tags... but - there might be a chance that the BB code is corrupted, i.e. I might be missing a closing element (e.g. [/LIST] is not there) in which case I would like to NOT replace the BB tag...
Basically, is there anyway to tell the XDocument not to escape tags, but rather treat them as subnodes?
//load the CSV file
List<string[]> rows = this.ParseCsvFile(originalFilePath);
//build the XML
for (int rowCount = 0; rowCount < rows.Count; rowCount++)
{
XElement xRow = new XElement(ROW_ELE);
string[] fields = rows[rowCount];
for (int colCount = 0; colCount < fields.Length; colCount++)
{
string text = fields[colCount];
//replace BB Code with XML tags inside current <Field> element
//TODO
XElement xField = new XElement(FIELD_ELE, text);
xRow.Add(xField);
}
xRoot.Add(xRow);
}
No comments:
Post a Comment