CodingIsFun
Programmer
Hi all experts
I am parsing through a 5 gig xml file, copying to another file as I go. I need to find a particular part of the xml and change a value for the new file.
Here is the error I get.
System.Xml.XmlException was unhandled
Message="Invalid character in the given encoding. Line 283, position 39709."
Source="System.Xml"
LineNumber=283
LinePosition=39709....
Unfortunately I can not find the foreign character.
Is there anyway to change the encoding of the XmlTextReader.
here is a snippet of my code, it fails at textReader.ReadOuterXml();
XmlTextReader textReader = new XmlTextReader(file_name_in);
textReader.Read();
while (!textReader.EOF)
{
XmlDocument doc = new XmlDocument();
/*try
{*/
string val = textReader.ReadOuterXml();
if (!val.Equals(""))//avoid empty reads
{
doc.LoadXml(val);
XmlNode inv = doc.SelectSingleNode(xpath);
if (inv != null)
{
string acid = inv.Attributes.GetNamedItem("acId").Value;
if (autopay_accounts.IndexOf(acid) != -1)
{
inv.Attributes.GetNamedItem("type").Value = "P";
log_writer.WriteLine("Changed account_id: " + acid + " to type=\"P\" ");
}
}
write.Write(doc.InnerXml);
//update the invoice element here.
}
else
{
write.Write(val);
}
/*
}
catch (Exception error)
{//ReadElementContentAsString()
log_writer.WriteLine("Error reading: " + textReader.);
}
*/
}
I have tested this on smaller files and it works fine. This gets through about 1.5 gigs before the error.
I have parsed line by line, which are .25 gigs per line to try and identify the un-recognizable character. I still can't find it.
Any help would be greatly appreciated.
thanks in advance..
I am parsing through a 5 gig xml file, copying to another file as I go. I need to find a particular part of the xml and change a value for the new file.
Here is the error I get.
System.Xml.XmlException was unhandled
Message="Invalid character in the given encoding. Line 283, position 39709."
Source="System.Xml"
LineNumber=283
LinePosition=39709....
Unfortunately I can not find the foreign character.
Is there anyway to change the encoding of the XmlTextReader.
here is a snippet of my code, it fails at textReader.ReadOuterXml();
XmlTextReader textReader = new XmlTextReader(file_name_in);
textReader.Read();
while (!textReader.EOF)
{
XmlDocument doc = new XmlDocument();
/*try
{*/
string val = textReader.ReadOuterXml();
if (!val.Equals(""))//avoid empty reads
{
doc.LoadXml(val);
XmlNode inv = doc.SelectSingleNode(xpath);
if (inv != null)
{
string acid = inv.Attributes.GetNamedItem("acId").Value;
if (autopay_accounts.IndexOf(acid) != -1)
{
inv.Attributes.GetNamedItem("type").Value = "P";
log_writer.WriteLine("Changed account_id: " + acid + " to type=\"P\" ");
}
}
write.Write(doc.InnerXml);
//update the invoice element here.
}
else
{
write.Write(val);
}
/*
}
catch (Exception error)
{//ReadElementContentAsString()
log_writer.WriteLine("Error reading: " + textReader.);
}
*/
}
I have tested this on smaller files and it works fine. This gets through about 1.5 gigs before the error.
I have parsed line by line, which are .25 gigs per line to try and identify the un-recognizable character. I still can't find it.
Any help would be greatly appreciated.
thanks in advance..