November 18, 2009 at 3:25 pm
Hi,
I have an XML file that has HTML tags in some of the elements . I have written a program in C# to parse the HTML chaaracters .
Below is a sample
static void Main(string[] args)
{
string strXML = "";
XmlTextReader textReader = new XmlTextReader("C:\\InputXML.xml");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(textReader);
StringWriter writer = new StringWriter();
xmlDoc.Save(writer);
strXML = writer.ToString();
strXML = strXML.Replace("<a>", "<a> ");
strXML = strXML.Replace("<a", "<a");
FileInfo t = new FileInfo("C:\\OutputXML.xml");
StreamWriter Tex = t.CreateText();
Tex.Write(strXML);
Tex.Close();
}}}
But when I escape in this code as I get an XML undeclared entity error .
Any help appreciated .
November 18, 2009 at 3:35 pm
Maybe I'm reading that wrong - , but two places dont' look right:
1. if you're worried about the XML being valid - why load the stuff into an XMLdocument BEFORE you run the cleanup process? I can't help but think it bombs there
2. your replacement commands do nothing - why?
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
November 19, 2009 at 8:35 am
Sorry, the replace should have been like this
strXML = strXML.Replace("</a>", "<"/a"> ");
strXML = strXML.Replace("<acronym>", "<"acronym"> ")
November 19, 2009 at 9:36 am
Have you tried sending ith through a generic string writer to do the replacements, and then push it so XML?
and - you need to escape the " or it will bomb (I realize the site is likely getting rid of the extra \)
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply