Could you post a short but complete program which demonstrates the
problem?
Seehttp://
www.pobox.com/~skeet/csharp/complete.htmlfor details of
what I mean by that.
Hi Jon
I meant to post the code but I was at home without it. The C# program
is dead simple and just reads the nodes, and it works fine except for
the CDATA. It did work and then suddenly stopped, so I probably
accidently changed it (the original code was two years old). So I am
sure it is a small change needed. The XML file is a data file of
bathroom data and has basic descriptions, images, and comments. There
are about a 1500 files to read and handle, so a program is needed.
I have searched google for relevant data on this and found various
combinations but nothing is really working for me. It is something
related to reading strings, values, attributes. I read several posts
of people having problems in parsing CDATA but the solutions seemed to
be use Value which does not work for me.
The key problems are with farbname (colour in German), kurztext (short
text), and langtext. I decided not to navigate the parent structure
and it seemed to make no difference, and I just used the nodenames.
Here is the code running under .NET 1.1, C#, Windows Forms (under
Windows XP):
<?xml version="1.0" encoding="UTF-16" ?>
- <produkt>
<produktid value="6858651" />
<artnr value="33304" />
<kombipr value="false" />
- <kurztext>
- <![CDATA[ Single-lever bath/shower mixer 1/2"
]]>
</kurztext>
<gewusst_wie value="false" />
- <internettext>
- <![CDATA[
]]>
</internettext>
- <stlb>
- <![CDATA[
]]>
</stlb>
<pid value="6858657" />
<dxf value="/dxf/1074194.zip" />
- <langtext>
- <![CDATA[ metal lever<br>46 mm ceramic cartridge with <br>Eco-
Override-Stop, with <b>GROHE SilkMove®</b><br>adjustable flow rate
limiter<br>adjustable minimum flow rate 2.5 l/min<br>automatic
diverter: bath/shower<br>integrated non-return valves <br>in the
shower outlet 1/2"<br>mousseur aerator (HP)<br>without connection
unions<br>optional temperature limiter<br>protected against
backflow<br>Min. recommended pressure 1.0 bar<br>Balanced hot and cold
supplies
]]>
</langtext>
<mbild value="./images/draw/Z33304001.jpg" online="./images/draw/
online/Z33304001.jpg" width="36" height="60" />
<stbild value="./images/strich/S33304001.gif" online="./images/
strich/online/S33304001.jpg" width="87" height="60" />
<swbild value="./images/sw/F33304001.gif" online="./images/sw/online/
F33304001.jpg" thumbnails="./images/sw/thumbnails/F33304001.jpg" />
<gruppe value="02" />
<designlinie value="05" />
<prodtyp value="05" />
<sge value="02" />
<montage value="01" />
<zapfstelle value="03" />
<linie value="D67" />
<design value="67" />
<brausen value="01" />
- <produktliniename>
- <![CDATA[ PL_Eurosmart
]]>
</produktliniename>
<produktlinienid value="6850046" />
- <produktlinientext>
- <![CDATA[ Eurosmart
]]>
</produktlinientext>
<ranking value="7" />
<pq value="./images/pq/EnglischUK/D33304.gif" online="./images/pq/
online/EnglischUK/D33304.jpg" />
- <farben>
- <farbe>
<produktid value="6858651" />
- <farbname>
- <![CDATA[ chrome
]]>
</farbname>
<schluessel value="001" />
<vvs value="" />
<pbild value="./images/prod/33304001.gif" online="./images/prod/
online/33304001.jpg" thumbnails="./images/prod/thumbnails/
33304001.jpg" />
<ranking value="0" />
<stueckliste value="true" />
<explozeichnung value="./images/explo/E33304001.jpg" online="./
images/explo/online/E33304001.jpg" width="44" height="60" />
<preis value="90.33" />
<preis2 value="" />
</farbe>
</farben>
</produkt>
private void handleGroheXML(string filePath1)
{
// write file
string thisOutFilePath = "c:\\grohe\\xml\\processed.txt";
FileStream fs = new
FileStream(thisOutFilePath,FileMode.Append,FileAccess.Write,FileShare.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(filePath1);
sw.Close();
// end write file
string thisXMLName="";
filePath1="C:\\grohe\\xml\\"+filePath1;
XmlTextReader reader = new XmlTextReader((filePath1));
reader.WhitespaceHandling=WhitespaceHandling.None;
XmlDocument xmlDoc = new XmlDocument();
int index1 = filePath1.IndexOf(".xml");
if (index1>0)
{
while(reader.Read())
{
//if (reader.NodeType == XmlNodeType.Element)
if (reader.LocalName.Length>0)
{
//////////Trace.Warn("reader.localname top =="+
reader.LocalName);
string thisNodeType = reader.NodeType.ToString();
thisXMLName = reader.LocalName;
if (thisXMLName == "farbname")
{
string xx="";
thisColour = reader.Value;
//string jj1 = reader.LocalName;
string jj="";
thisColour = reader.ReadString();
//thisColour=reader.GetAttribute("CDATA");
thisPOID = handleColour(thisColour);
}
if (thisXMLName == "produktid")
{
string hh1="";
}
if (thisXMLName == "artnr")
{
thisPartNumber = reader.GetAttribute("value");
thisManPartNumber = thisPartNumber;
//string thisNodeType = reader.NodeType.ToString();
//ReadAttributeValue("value");
//string gg="";
}
if (thisXMLName == "kurztext")
{
thisShortDesc = reader.ReadString();
thisShortDesc=thisShortDesc.Replace("<b>","");
thisShortDesc=thisShortDesc.Replace("</b>","");
thisShortDesc=thisShortDesc.Replace("<Normal>","");
thisShortDesc=thisShortDesc.Replace("</Normal>","");
// trevor
thisPartDesc = thisShortDesc;
if (thisShortDesc.Length>50)
{
thisShortDesc = thisShortDesc.Substring(0,50);
}
//string thisNodeType = reader.NodeType.ToString();
//ReadAttributeValue("value");
}
if (thisXMLName == "gruppe")
{
thisFamily = reader.GetAttribute("value");
//string thisNodeType = reader.NodeType.ToString();
//ReadAttributeValue("value");
}
if (thisXMLName == "langtext")
{
thisCommentStr = reader.ReadString();
//string thisNodeType = reader.NodeType.ToString();
//ReadAttributeValue("value");
}
if (thisXMLName == "pbild")
{
// process pbild
}
// get schusell prefix
if (thisXMLName == "mbild")
{
thisSizeImage = reader.GetAttribute("value");
thisSizeImage=thisSizeImage.Replace("./images/draw/","");
}
if (thisXMLName == "stbild")
{
thisLineImage = reader.GetAttribute("value");
thisLineImage=thisLineImage.Replace("./images/strich/","");
}
if (thisXMLName == "swbild")
{
thisOrgPic = reader.GetAttribute("value");
thisOrgPic=thisOrgPic.Replace("./images/sw/","");
}
if (thisXMLName == "explozeichnung")
{
thisInstallationPic = reader.GetAttribute("value");
thisInstallationPic=thisInstallationPic.Replace("./images/
explo/","");
}
if (thisXMLName == "pq")
{
thisFlowRatePic = reader.GetAttribute("value");
thisFlowRatePic=thisFlowRatePic.Replace("./images/pq/","");
thisFlowRatePic=thisFlowRatePic.Replace("./images/prod/","");
}
if (thisXMLName == "produktliniename")
{
thisRange = reader.ReadString();
}
if (thisXMLName == "schluessel")
{
thisPartNumberOption= reader.GetAttribute("value");
}
if (thisXMLName == "preis")
{
string thisPriceS= reader.GetAttribute("value");
// process price
//if (thisXMLName == "farben")
//{
// get farbe record
// reader.ReadStartElement("farbname");
//
// string thisData = reader.ReadString();
//
// reader.ReadEndElement();
//}
}
}
}
}
}