473,396 Members | 1,706 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,396 software developers and data experts.

XML reader question

I'm using XmlReader to read an XMl String such as this one:
Expand|Select|Wrap|Line Numbers
  1. <XML_REQUEST>
  2. <USER_ID>Admin</USER_ID>
  3. <USER_PW>Test123%</USER_PW>
  4. <COMMAND>1</COMMAND>
  5. <PRESENT_FLAG>1</PRESENT_FLAG>
  6. <INVOICE></INVOICE>
  7. <TRANS_AMOUNT>6.00</TRANS_AMOUNT>
  8. </XML_REQUEST>
You can see that there is an empty tag on invoice.

I'm reading the string like this:

Expand|Select|Wrap|Line Numbers
  1.  while (reader.Read())
  2.           {
  3.             switch (reader.NodeType)
  4.             {
  5.               //write start element
  6.               case XmlNodeType.Element:
  7.                  /// some other cases up here
  8.                 default:
  9.                       localname = reader.LocalName;
  10.                       reader.Read();
  11.                       localvalue = reader.Value;
  12.                       if (string.IsNullOrEmpty(reader.Value) == false)
  13.                       {
  14.                           writer.WriteStartElement(localname);
  15.                           writer.WriteString(localvalue);
  16.                           writer.WriteEndElement();
  17.                       }
  18.                     break;
  19.  
  20.  
Is there any way to tell if the value is going to be empty before I call the reader.Read() in bold. Its screwing up the reading of the next value in trans amount. I tried reader.HasValue but that didn't work
Nov 26 '07 #1
3 1083
Shashi Sadasivan
1,435 Expert 1GB
have you tried
reader.InnerText or reader.innerXML ?
Nov 26 '07 #2
have you tried
reader.InnerText or reader.innerXML ?
I don't see those properties on the reader.
Nov 27 '07 #3
Shashi Sadasivan
1,435 Expert 1GB
Wooops....
Sorry about that one....
My mistake....
its a property of XMLNode....(which is a part of DOM)

I havent looked at the SAX Model in .Net yet...
Hope someone else could help you with that (i will try to look at it later on)
Nov 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Aaron | last post by:
The example you give me worked until I tried to open an xml file with nested tags. for example the xml looks like this <book> <genre> <action>ABC</action> <bio>DFK</bio> </genre> </book>
1
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
1
by: Mike P | last post by:
I'm using 1 connection to open 3 separate data readers to read data into 3 data grids. However, when I try to use the 2nd reader it says that the first reader must be closed. So I use Close() to...
3
by: Javier Camacho | last post by:
Hi , We want to deploy a Microsoft Fingerprint solution in order to authenticate our ASP.NET applications. I want to know if exists a SDK to Microsoft FingerPrint Reader or if We have to use the...
6
by: roblugt | last post by:
I have what I imagine is a well-known .Net networking problem, but even though I've Googled for some time I've not yet come across a thread where this has been fully explained... There is a...
3
by: John | last post by:
Hi I am getting the System.IndexOutOfRangeException was unhandled error on the last line of below code; Cmd = New OleDb.OleDbCommand("SELECT FROM ", LocalConn) Reader = Cmd.ExecuteReader()...
5
by: cjl | last post by:
P: Stupid question: reader = csv.reader(open('somefile.csv')) for row in reader: do something Any way to determine the "length" of the reader (the number of rows) before iterating through...
1
by: Daniel | last post by:
is a reader automaticaly disposed if the connection it is associated with is closed? what will happen if an app: while true open connection open reader close connection end while
0
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi all people, everybody, We have multiple versions of Acrobat Reader from 5.x to 8.x, I want to create a method in C# or VB.NET to check to see if the registry key for the versions...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.