Reading node values from xml



I have an XML File and the format is



<?xml version="1.0" encoding="utf-8"?>
<ROWDATA>
<ROW ORGCODE="00001" BRANCHCODE="00002"/>
<ROW ORGCODE="00001" BRANCHCODE="00003"/>
<ROW ORGCODE="00001" BRANCHCODE="00004"/>
<<ROW ORGCODE="00001" BRANCHCODE="00005"/>
</ROWDATA>


while reading the xml , only 1st and 3rd node (ORGCODE="00001" ,BRANCHCODE="00002" and ORGCODE="00001",BRANCHCODE="00004") are fetching.Need to read every node


My code structure is



using (StreamReader oReader = new StreamReader(FileName, Encoding.GetEncoding("ISO-8859-1")))
{
int i = 0;
int j = 0;
XmlReaderSettings xrs = new XmlReaderSettings();
xrs.CheckCharacters = false;
xrs.ConformanceLevel = ConformanceLevel.Document;

using (XmlReader reader = XmlReader.Create(oReader, xrs))
{
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
switch (reader.LocalName.ToUpper())
{
case "ROW":
//Insert details to database
if (retval == "100")
{
i++;
}
j++;
obj = null;
break;
}
break;
}
}
}
}

No comments:

Post a Comment