473,386 Members | 1,830 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.

Get Element Value

Jay
In a loop like so:

....
xmlr=cmd.executexmlreader()
xmlr.read()
do while xmlr.readstate <> xml.readstate.endoffile

loop

How do I return each individual element name and value from a document like
so:

<Customer>
<custno>2</custno>
<lname>Doe</lname>
<fname>John</fname>
<address>123 4th st.</address>
</customer>
So the result I need in the loop is (output to textbox):

custno: 2
lname: Doe
....
Thanks a lot.

May 17 '06 #1
8 1242
while(reader.Read())
{
if(reader.NodeType == XmlNodeType.Element)
{
_name = reader.Name;
if(reader.read())
{
if(reader.NodeType == XmlNodeType.Text)
{
_value = reader.Value;
}
}
}
}

or

string _name;
string _value;

while(r.Read())
{
switch(reader.NodeType)
{
XmlNodeType.Element: _name = reader.Name;
break;
XmlNodeType.Text: if(_name != null)
{
_value = reader.Value;
_name = null;
} // Reset the _name after the value has
been found
}
}
HTH

--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
"Jay" <msnews.microsoft.com> wrote in message
news:eK**************@TK2MSFTNGP04.phx.gbl...
In a loop like so:

...
xmlr=cmd.executexmlreader()
xmlr.read()
do while xmlr.readstate <> xml.readstate.endoffile

loop

How do I return each individual element name and value from a document
like so:

<Customer>
<custno>2</custno>
<lname>Doe</lname>
<fname>John</fname>
<address>123 4th st.</address>
</customer>
So the result I need in the loop is (output to textbox):

custno: 2
lname: Doe
...
Thanks a lot.


May 18 '06 #2
while(reader.Read())
{
if(reader.NodeType == XmlNodeType.Element)
{
_name = reader.Name;
if(reader.read())
{
if(reader.NodeType == XmlNodeType.Text)
{
_value = reader.Value;
}
}
}
}

or

string _name;
string _value;

while(r.Read())
{
switch(reader.NodeType)
{
XmlNodeType.Element: _name = reader.Name;
break;
XmlNodeType.Text: if(_name != null)
{
_value = reader.Value;
_name = null;
} // Reset the _name after the value has
been found
}
}
HTH

--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
"Jay" <msnews.microsoft.com> wrote in message
news:eK**************@TK2MSFTNGP04.phx.gbl...
In a loop like so:

...
xmlr=cmd.executexmlreader()
xmlr.read()
do while xmlr.readstate <> xml.readstate.endoffile

loop

How do I return each individual element name and value from a document
like so:

<Customer>
<custno>2</custno>
<lname>Doe</lname>
<fname>John</fname>
<address>123 4th st.</address>
</customer>
So the result I need in the loop is (output to textbox):

custno: 2
lname: Doe
...
Thanks a lot.


May 18 '06 #3
Jay
Thanks for the reply.

This seems to work well, however, I am faced with a problem...

I need to get the etire ReadOuterXML for each of the individual records as
well as a few of the element values within that record.

So with XML like so:

<Customer>
<custno>2</custno>
<lname>Doe</lname>
<fname>John</fname>
<address>123 4th st.</address>
</customer>
<Customer>
<custno>3</custno>
<lname>Smith</lname>
<fname>Terry</fname>
<address>456 7th St.</address>
</customer>

I need to return (in a loop) something like this:

varOuterXML =
"<Customer><custno>2</custno><lname>Doe</lname><fname>John</fname><address>123
4th st.</address></customer>"
varLName="Doe"
varFName="John"

varOuterXML =
"<Customer><custno>3</custno><lname>Smith</lname><fname>Terry</fname><address>456
7th St.</address></customer>"
varLName="Smith"
varFName="Terry"
I am using while xmlreader.readstate <> xml.readstate.endoffile but cannot
seem to get this to work together.

Any suggestions would be greatly appreciated.

Thanks a lot.


"Gaurav Vaish (EduJini.IN)" <ga*****************@nospam.gmail.com> wrote in
message news:uw*************@TK2MSFTNGP04.phx.gbl...
while(reader.Read())
{
if(reader.NodeType == XmlNodeType.Element)
{
_name = reader.Name;
if(reader.read())
{
if(reader.NodeType == XmlNodeType.Text)
{
_value = reader.Value;
}
}
}
}

or

string _name;
string _value;

while(r.Read())
{
switch(reader.NodeType)
{
XmlNodeType.Element: _name = reader.Name;
break;
XmlNodeType.Text: if(_name != null)
{
_value = reader.Value;
_name = null;
} // Reset the _name after the value
has been found
}
}
HTH

--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
"Jay" <msnews.microsoft.com> wrote in message
news:eK**************@TK2MSFTNGP04.phx.gbl...
In a loop like so:

...
xmlr=cmd.executexmlreader()
xmlr.read()
do while xmlr.readstate <> xml.readstate.endoffile

loop

How do I return each individual element name and value from a document
like so:

<Customer>
<custno>2</custno>
<lname>Doe</lname>
<fname>John</fname>
<address>123 4th st.</address>
</customer>
So the result I need in the loop is (output to textbox):

custno: 2
lname: Doe
...
Thanks a lot.



May 18 '06 #4
Don't use single _name and _value.
When you encounter an element with the name Customer, jump into another
function where you keep track of all entries.

Should be simple.
--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
"Jay" <msnews.microsoft.com> wrote in message
news:uT**************@TK2MSFTNGP05.phx.gbl...
Thanks for the reply.

This seems to work well, however, I am faced with a problem...

I need to get the etire ReadOuterXML for each of the individual records as
well as a few of the element values within that record.

So with XML like so:

<Customer>
<custno>2</custno>
<lname>Doe</lname>
<fname>John</fname>
<address>123 4th st.</address>
</customer>
<Customer>
<custno>3</custno>
<lname>Smith</lname>
<fname>Terry</fname>
<address>456 7th St.</address>
</customer>

I need to return (in a loop) something like this:

varOuterXML =
"<Customer><custno>2</custno><lname>Doe</lname><fname>John</fname><address>123
4th st.</address></customer>"
varLName="Doe"
varFName="John"

varOuterXML =
"<Customer><custno>3</custno><lname>Smith</lname><fname>Terry</fname><address>456
7th St.</address></customer>"
varLName="Smith"
varFName="Terry"
I am using while xmlreader.readstate <> xml.readstate.endoffile but cannot
seem to get this to work together.

Any suggestions would be greatly appreciated.

Thanks a lot.


"Gaurav Vaish (EduJini.IN)" <ga*****************@nospam.gmail.com> wrote
in message news:uw*************@TK2MSFTNGP04.phx.gbl...
while(reader.Read())
{
if(reader.NodeType == XmlNodeType.Element)
{
_name = reader.Name;
if(reader.read())
{
if(reader.NodeType == XmlNodeType.Text)
{
_value = reader.Value;
}
}
}
}

or

string _name;
string _value;

while(r.Read())
{
switch(reader.NodeType)
{
XmlNodeType.Element: _name = reader.Name;
break;
XmlNodeType.Text: if(_name != null)
{
_value = reader.Value;
_name = null;
} // Reset the _name after the value
has been found
}
}
HTH

--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
"Jay" <msnews.microsoft.com> wrote in message
news:eK**************@TK2MSFTNGP04.phx.gbl...
In a loop like so:

...
xmlr=cmd.executexmlreader()
xmlr.read()
do while xmlr.readstate <> xml.readstate.endoffile

loop

How do I return each individual element name and value from a document
like so:

<Customer>
<custno>2</custno>
<lname>Doe</lname>
<fname>John</fname>
<address>123 4th st.</address>
</customer>
So the result I need in the loop is (output to textbox):

custno: 2
lname: Doe
...
Thanks a lot.




May 18 '06 #5
Jay
Thank you for the reply. Not quite sure what you mean.

I need both the entire outerxml as well as a few individual element values.
Would I use a loop inside the loop?

"Gaurav Vaish (EduJini.IN)" <ga*****************@nospam.gmail.com> wrote in
message news:eh**************@TK2MSFTNGP03.phx.gbl...
Don't use single _name and _value.
When you encounter an element with the name Customer, jump into another
function where you keep track of all entries.

Should be simple.
--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
"Jay" <msnews.microsoft.com> wrote in message
news:uT**************@TK2MSFTNGP05.phx.gbl...
Thanks for the reply.

This seems to work well, however, I am faced with a problem...

I need to get the etire ReadOuterXML for each of the individual records
as well as a few of the element values within that record.

So with XML like so:

<Customer>
<custno>2</custno>
<lname>Doe</lname>
<fname>John</fname>
<address>123 4th st.</address>
</customer>
<Customer>
<custno>3</custno>
<lname>Smith</lname>
<fname>Terry</fname>
<address>456 7th St.</address>
</customer>

I need to return (in a loop) something like this:

varOuterXML =
"<Customer><custno>2</custno><lname>Doe</lname><fname>John</fname><address>123
4th st.</address></customer>"
varLName="Doe"
varFName="John"

varOuterXML =
"<Customer><custno>3</custno><lname>Smith</lname><fname>Terry</fname><address>456
7th St.</address></customer>"
varLName="Smith"
varFName="Terry"
I am using while xmlreader.readstate <> xml.readstate.endoffile but
cannot seem to get this to work together.

Any suggestions would be greatly appreciated.

Thanks a lot.


"Gaurav Vaish (EduJini.IN)" <ga*****************@nospam.gmail.com> wrote
in message news:uw*************@TK2MSFTNGP04.phx.gbl...
while(reader.Read())
{
if(reader.NodeType == XmlNodeType.Element)
{
_name = reader.Name;
if(reader.read())
{
if(reader.NodeType == XmlNodeType.Text)
{
_value = reader.Value;
}
}
}
}

or

string _name;
string _value;

while(r.Read())
{
switch(reader.NodeType)
{
XmlNodeType.Element: _name = reader.Name;
break;
XmlNodeType.Text: if(_name != null)
{
_value = reader.Value;
_name = null;
} // Reset the _name after the value
has been found
}
}
HTH

--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
"Jay" <msnews.microsoft.com> wrote in message
news:eK**************@TK2MSFTNGP04.phx.gbl...
In a loop like so:

...
xmlr=cmd.executexmlreader()
xmlr.read()
do while xmlr.readstate <> xml.readstate.endoffile

loop

How do I return each individual element name and value from a document
like so:

<Customer>
<custno>2</custno>
<lname>Doe</lname>
<fname>John</fname>
<address>123 4th st.</address>
</customer>
So the result I need in the loop is (output to textbox):

custno: 2
lname: Doe
...
Thanks a lot.




May 18 '06 #6
You need to keep a track of all the values in a buffer.
At the same time, you need to keep storing the individual values.

Similar to what the XmlDocument does.

btw, just wondering, why don't you directly use XmlDocument? If the XML file
a huge one?
--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
"Jay" <msnews.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Thank you for the reply. Not quite sure what you mean.

I need both the entire outerxml as well as a few individual element
values. Would I use a loop inside the loop?

"Gaurav Vaish (EduJini.IN)" <ga*****************@nospam.gmail.com> wrote
in message news:eh**************@TK2MSFTNGP03.phx.gbl...
Don't use single _name and _value.
When you encounter an element with the name Customer, jump into another
function where you keep track of all entries.

Should be simple.
--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
"Jay" <msnews.microsoft.com> wrote in message
news:uT**************@TK2MSFTNGP05.phx.gbl...
Thanks for the reply.

This seems to work well, however, I am faced with a problem...

I need to get the etire ReadOuterXML for each of the individual records
as well as a few of the element values within that record.

So with XML like so:

<Customer>
<custno>2</custno>
<lname>Doe</lname>
<fname>John</fname>
<address>123 4th st.</address>
</customer>
<Customer>
<custno>3</custno>
<lname>Smith</lname>
<fname>Terry</fname>
<address>456 7th St.</address>
</customer>

I need to return (in a loop) something like this:

varOuterXML =
"<Customer><custno>2</custno><lname>Doe</lname><fname>John</fname><address>123
4th st.</address></customer>"
varLName="Doe"
varFName="John"

varOuterXML =
"<Customer><custno>3</custno><lname>Smith</lname><fname>Terry</fname><address>456
7th St.</address></customer>"
varLName="Smith"
varFName="Terry"
I am using while xmlreader.readstate <> xml.readstate.endoffile but
cannot seem to get this to work together.

Any suggestions would be greatly appreciated.

Thanks a lot.


"Gaurav Vaish (EduJini.IN)" <ga*****************@nospam.gmail.com> wrote
in message news:uw*************@TK2MSFTNGP04.phx.gbl...
while(reader.Read())
{
if(reader.NodeType == XmlNodeType.Element)
{
_name = reader.Name;
if(reader.read())
{
if(reader.NodeType == XmlNodeType.Text)
{
_value = reader.Value;
}
}
}
}

or

string _name;
string _value;

while(r.Read())
{
switch(reader.NodeType)
{
XmlNodeType.Element: _name = reader.Name;
break;
XmlNodeType.Text: if(_name != null)
{
_value = reader.Value;
_name = null;
} // Reset the _name after the value
has been found
}
}
HTH

--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
"Jay" <msnews.microsoft.com> wrote in message
news:eK**************@TK2MSFTNGP04.phx.gbl...
> In a loop like so:
>
> ...
> xmlr=cmd.executexmlreader()
> xmlr.read()
> do while xmlr.readstate <> xml.readstate.endoffile
>
> loop
>
> How do I return each individual element name and value from a document
> like so:
>
> <Customer>
> <custno>2</custno>
> <lname>Doe</lname>
> <fname>John</fname>
> <address>123 4th st.</address>
> </customer>
>
>
> So the result I need in the loop is (output to textbox):
>
> custno: 2
> lname: Doe
> ...
>
>
> Thanks a lot.
>
>
>
>
>



May 19 '06 #7
The XML I'm using comes from SQL Server 2005 and isn't very large at all. I
am having a difficult time with the loop used to capture the individual
element values as well as the outerxml. Would you happen to know of an
example illustrating this or tutorials on accomplishing this? Thank you
very much.
"Gaurav Vaish (EduJini.IN)" <ga*****************@nospam.gmail.com> wrote in
message news:uS**************@TK2MSFTNGP02.phx.gbl...
You need to keep a track of all the values in a buffer.
At the same time, you need to keep storing the individual values.

Similar to what the XmlDocument does.

btw, just wondering, why don't you directly use XmlDocument? If the XML
file a huge one?
--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
"Jay" <msnews.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Thank you for the reply. Not quite sure what you mean.

I need both the entire outerxml as well as a few individual element
values. Would I use a loop inside the loop?

"Gaurav Vaish (EduJini.IN)" <ga*****************@nospam.gmail.com> wrote
in message news:eh**************@TK2MSFTNGP03.phx.gbl...
Don't use single _name and _value.
When you encounter an element with the name Customer, jump into another
function where you keep track of all entries.

Should be simple.
--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
"Jay" <msnews.microsoft.com> wrote in message
news:uT**************@TK2MSFTNGP05.phx.gbl...
Thanks for the reply.

This seems to work well, however, I am faced with a problem...

I need to get the etire ReadOuterXML for each of the individual records
as well as a few of the element values within that record.

So with XML like so:

<Customer>
<custno>2</custno>
<lname>Doe</lname>
<fname>John</fname>
<address>123 4th st.</address>
</customer>
<Customer>
<custno>3</custno>
<lname>Smith</lname>
<fname>Terry</fname>
<address>456 7th St.</address>
</customer>

I need to return (in a loop) something like this:

varOuterXML =
"<Customer><custno>2</custno><lname>Doe</lname><fname>John</fname><address>123
4th st.</address></customer>"
varLName="Doe"
varFName="John"

varOuterXML =
"<Customer><custno>3</custno><lname>Smith</lname><fname>Terry</fname><address>456
7th St.</address></customer>"
varLName="Smith"
varFName="Terry"
I am using while xmlreader.readstate <> xml.readstate.endoffile but
cannot seem to get this to work together.

Any suggestions would be greatly appreciated.

Thanks a lot.


"Gaurav Vaish (EduJini.IN)" <ga*****************@nospam.gmail.com>
wrote in message news:uw*************@TK2MSFTNGP04.phx.gbl...
> while(reader.Read())
> {
> if(reader.NodeType == XmlNodeType.Element)
> {
> _name = reader.Name;
> if(reader.read())
> {
> if(reader.NodeType == XmlNodeType.Text)
> {
> _value = reader.Value;
> }
> }
> }
> }
>
> or
>
> string _name;
> string _value;
>
> while(r.Read())
> {
> switch(reader.NodeType)
> {
> XmlNodeType.Element: _name = reader.Name;
> break;
> XmlNodeType.Text: if(_name != null)
> {
> _value = reader.Value;
> _name = null;
> } // Reset the _name after the
> value has been found
> }
> }
>
>
> HTH
>
> --
> Happy Hacking,
> Gaurav Vaish
> http://www.mastergaurav.org
> http://www.edujini.in
> -------------------
>
>
> "Jay" <msnews.microsoft.com> wrote in message
> news:eK**************@TK2MSFTNGP04.phx.gbl...
>> In a loop like so:
>>
>> ...
>> xmlr=cmd.executexmlreader()
>> xmlr.read()
>> do while xmlr.readstate <> xml.readstate.endoffile
>>
>> loop
>>
>> How do I return each individual element name and value from a
>> document like so:
>>
>> <Customer>
>> <custno>2</custno>
>> <lname>Doe</lname>
>> <fname>John</fname>
>> <address>123 4th st.</address>
>> </customer>
>>
>>
>> So the result I need in the loop is (output to textbox):
>>
>> custno: 2
>> lname: Doe
>> ...
>>
>>
>> Thanks a lot.
>>
>>
>>
>>
>>
>
>



May 19 '06 #8
I'd suggest using XmlDocument in that case.

Examples... I'd not be aware. I'm a nerd ;-)
--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
<msnews.microsoft.com> wrote in message
news:uv****************@TK2MSFTNGP05.phx.gbl...
The XML I'm using comes from SQL Server 2005 and isn't very large at all.
I am having a difficult time with the loop used to capture the individual
element values as well as the outerxml. Would you happen to know of an
example illustrating this or tutorials on accomplishing this? Thank you
very much.

May 19 '06 #9

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

Similar topics

0
by: Ingrid | last post by:
Am I right in thinking that datatyping at element level ie <xs:element name="num" type="xs:integer"> and specifying a choice of attribute values ie <xs:attribute name="kind"> <xs:simpleType>...
4
by: celerystick | last post by:
This is an xsl question, comp.infosystems.www.authoring.stylesheets were not able to help , here goes .... With one xml file containing repeated element <subject>: ...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
6
by: Luke Dalessandro | last post by:
I'm not sure if this is the correct forum for platform specific (Mozilla/Firefox) javascript problems, so just shout and point me to the correct newsgroup if I'm being bad. Here's the deal... ...
1
by: pjeung | last post by:
Say that I have an element <elementA> that has several layers of subelements. In System.Xml.XmlDocument and related classes, how do I rename <elementA> to <elementB> leaving the subelements intact?
1
by: Maksim | last post by:
Trying to find out a way how to restrict value of the element by name of an element, it might be not even possible, but anyhow. Let's consider following snippet: <xs:element name="tag1"...
4
by: eksamor | last post by:
I have a simple linked list: struct element { struct element *next; int start; }; struct list { struct element *head;
3
markmcgookin
by: markmcgookin | last post by:
Hi, I have the following XML <AnswerList xmlns="http://tempuri.org/ALPS_Assessmentv1p1_RESCO_Schema.xsd"> <DateTimeLastSaved>12:12:12 1900</DateTimeLastSaved> <UserName>Bob</UserName>...
2
dlite922
by: dlite922 | last post by:
Before traversing my code, here's what my goal is and what this function does: I have a table of fields that dynamically grows as the user enters information. A minimum of 3 rows must always...
2
by: mlb5000 | last post by:
I seem to be having issues validating an XML document using my schema. Both are below: The Schema: <?xml version="1.0" encoding="UTF-8"?> <xs:schema...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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.