nvbob
asked on
Use ReadToFollow when character case is not known
I am reading through an XML files using ReadToFollow. Works great. The challenge is that the XML file can come from many different sources. Yes they all are supposed to follow a standard but reality is that not everyone follows the standards. In any case the element names are not all cased the same. For example they can be <product>, <Product> or <PRODUCT>. Is there a way to use ReadToFollow but get around the case sensitivity?
Easy example of code being used –
Int64 recordCount = 0;
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.DtdProcessi ng = DtdProcessing.Ignore;
readerSettings.Conformance Level = ConformanceLevel.Document;
readerSettings.IgnoreWhite space = true;
readerSettings.IgnoreComme nts = true;
readerSettings.XmlResolver = null;
try
{
XmlReader reader = XmlReader.Create(inputFile Name, readerSettings);
while (reader.ReadToFollowing("p roduct"))
{
recordCount++;
}
return recordCount;
}
catch (IOException ex)
{
MessageBox.Show(ex.ToStrin g(), "There was an error in getProductCount");
return 0;
}
Easy example of code being used –
Int64 recordCount = 0;
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.DtdProcessi
readerSettings.Conformance
readerSettings.IgnoreWhite
readerSettings.IgnoreComme
readerSettings.XmlResolver
try
{
XmlReader reader = XmlReader.Create(inputFile
while (reader.ReadToFollowing("p
{
recordCount++;
}
return recordCount;
}
catch (IOException ex)
{
MessageBox.Show(ex.ToStrin
return 0;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nice clean approach.
Thanks
Thanks
so, the correct solution is: get all your input source HAVE to follow the same rules.
alternative is to pre-parse the xml to "uppercase" all the XML node names and attributes, OR not to use ReadToFollowing ...