473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

xmlNodeReader question

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,
Robin
Dec 7 '05 #1
3 1513
could you post the while loop code that you are using.

thanks,
swapna

"adhag" <ad***@discussions.microsoft.com> wrote in message
news:2C**********************************@microsof t.com...
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,
Robin

Dec 8 '05 #2
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;



}
"swapna guddanti [MSFT]" wrote:
could you post the while loop code that you are using.

thanks,
swapna

"adhag" <ad***@discussions.microsoft.com> wrote in message
news:2C**********************************@microsof t.com...
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,
Robin


Dec 8 '05 #3
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

"adhag" <ad***@discussions.microsoft.com> wrote in message
news:2C**********************************@microsof t.com...
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;



}
"swapna guddanti [MSFT]" wrote:
could you post the while loop code that you are using.

thanks,
swapna

"adhag" <ad***@discussions.microsoft.com> wrote in message
news:2C**********************************@microsof t.com...
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,
Robin


Dec 8 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
0
by: Brian Rogers | last post by:
To whom it may concern: Can anyone explain this behaviour in serialization and deserialization? I serialize an object using an XML serializer. I de-serialize the object from a StringReader and...
4
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
1
by: Kris Desmadryl | last post by:
I want to loop all nodes of an xml file, because I want to search the content for a certain search pattern. I did something like this : reader = New XmlNodeReader(doc) While reader.Read() Select...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
4
by: David | last post by:
All I have an XML document as illustrated in the extract below. I am trying to use the XmlNodeReader to extract information from the document. What I am having trouble with is when I read the...
4
by: Samuel R. Neff | last post by:
I'm deserializing an XML file. If I pass a Stream to the file directly to the deserializer as follows it works fine: o = (New XmlSerializer( GetType(...
1
by: WalterWalt | last post by:
Below is a part of my xml file returned from a webservice. Instead of converting to a datatable and going through it a record at a time checking if ClientCodeType = "Balloon_Type" and ClientCode =...
10
by: jambalapamba | last post by:
I am trying to skip element in xml document where style attribute is VISIBILITY: hidden or DISPLAY: none. In the following example i want to skip the last two elements but when i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.