Groups | Blog | Home
all groups > dotnet xml > december 2005 >

dotnet xml : xmlNodeReader question


adhag
12/7/2005 12:26:02 PM
Hi

I am trying to parse through a large file in pieces using the xmlNodeReader.
I only need it to be forward only and performance is the key but I am having
a problem trying to get all the information out of my xml file.

For arguments sake my sample xml file looks like this
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<row value="123">
<errorcol e_w_flag="e" value="10003" col="5"/>

<cd>3391214</cd>
<cd>M.A. Weatherbie & Co., Inc. - Spec Growth 2</cd>
<cd>3.03</cd>
<cd> </cd>
<cd>10/26/2005</cd>
<cd>USD</cd>
<cd>PORT</cd>
<cd>Q</cd>
<cd> </cd>
<cd> </cd>
</row>

If I try to read this the errcol tag is not read. It goes directly from the
row to the cd tags. Any thoughts? I am doing a simple while reader.read
which is working and using a switch to interrogate the elements. I have
some suspicions but could use some real help.

Thanks,
swapna guddanti [MSFT]
12/8/2005 10:14:47 AM
could you post the while loop code that you are using.

thanks,
swapna

[quoted text, click to view]

adhag
12/8/2005 10:26:02 AM
I am using log4net to write to a file rather than the console. Otherwise it
is the example from the book.

while(x.Read())

{

// log.Debug(("Name equals: " + x.Name + " string
value: " + x.ReadString() )) ;

switch (x.NodeType)

{

case XmlNodeType.Element:



log.Debug("Element: " + x.Name);





if (x.HasAttributes)

{

for(int i = 0; i <
x.AttributeCount; i++)

{


log.Debug(string.Format("attribute number
{0}\tvalue={1}",i,x.GetAttribute(i)));

}

}

log.Debug("Element ReadString: " +
x.ReadString()) ;



break;

case XmlNodeType.Text:

//Console.Write(x.Value);

log.Debug("xmlNodetype: " +
x.ReadString());

break;

case XmlNodeType.CDATA:

//Console.Write(x.Value);

log.Debug("CData: " + x.ReadString());

break;

case XmlNodeType.ProcessingInstruction:

//Console.Write("<?{0} {1}?>", x.Name,
x.Value);

log.Debug("Processing Instructions: " +
x.Name + "" + x.ReadString());

break;

case XmlNodeType.Comment:

//Console.Write("<!--{0}-->", x.Value);

log.Debug("Comment: " + x.ReadString());

break;

case XmlNodeType.XmlDeclaration:

//Console.Write("<?xml version='1.0'?>");

log.Debug("xmlDeclaration " );

break;

case XmlNodeType.Document: break; case
XmlNodeType.EndElement:

//Console.Write("</{0}>", x.Name);

log.Debug("Document: " + x.ReadString());

break;







}


[quoted text, click to view]
swapna guddanti [MSFT]
12/8/2005 10:53:51 AM
The problem here is :
you are using ReadString() to get the value of the nodes. ReadString()
function reads the value as string and moves the context to next node.
So when you do another read() inside while(), the element in between gets
missed.
replace ReadString() with Value in your code and it should work fine.

hope this helps,
swapna

[quoted text, click to view]

AddThis Social Bookmark Button