471,089 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Getting attributes(I think) from XMLReader

Hi All,
I need a few suggestions. I have the following XML segment:
<LookUp>
<ControlType>CheckBoxGroup</ControlType>
<DBField>LastMedDate</DBField>
<ControlName>cmbGoal1</ControlName>
<Values VALUE="0" BookMark="Goal1Progress"/>
<Values VALUE="1" BookMark="Goal1NoProgress"/>
<Values VALUE="2" BookMark="Goal1NA"/>
</LookUp>
I have code that will read everything except the "Values" elements. Here is
the code:
While reader.Read()
Select Case (reader.NodeType)
Case XmlNodeType.Element
If (reader.Name = "DBField") Then
ReportElement.DBField() = reader.ReadElementString()
End If
If (reader.Name = "BookMark") Then
ReportElement.BookMark = reader.ReadElementString()
End If
If (reader.Name = "ControlName") Then
ReportElement.ControlName = reader.ReadElementString()
End If
If (reader.Name = "ColumnIndex") Then
ReportElement.ColumnIndex = reader.ReadElementString()
End If
If (reader.Name = "ControlType") Then
ReportElement.ControlType = reader.ReadElementString()
End If
If (reader.Name = "Values") Then
ReportElement.AddValue (0, reader.ReadElementString())
End If
case XmlNodeType.EndElement
If (reader.Name = "LookUp") then
al.Add(ReportElement)
ReportElement.Reset()
End If
End Select
End While

I've tried a few different things to get the Values elements such as:
reader.GetAttribute("BookMark")
But it returns "Nothing" in the Command window.
Could someone please let me know how to get the values element. Thanks
Michael

Nov 12 '05 #1
6 1699
I think those nodes would be of type attribute. Put in a case statement to
handle this type in your code.

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...
Hi All,
I need a few suggestions. I have the following XML segment:
<LookUp>
<ControlType>CheckBoxGroup</ControlType>
<DBField>LastMedDate</DBField>
<ControlName>cmbGoal1</ControlName>
<Values VALUE="0" BookMark="Goal1Progress"/>
<Values VALUE="1" BookMark="Goal1NoProgress"/>
<Values VALUE="2" BookMark="Goal1NA"/>
</LookUp>
I have code that will read everything except the "Values" elements. Here
is
the code:
While reader.Read()
Select Case (reader.NodeType)
Case XmlNodeType.Element
If (reader.Name = "DBField") Then
ReportElement.DBField() = reader.ReadElementString()
End If
If (reader.Name = "BookMark") Then
ReportElement.BookMark = reader.ReadElementString()
End If
If (reader.Name = "ControlName") Then
ReportElement.ControlName = reader.ReadElementString()
End If
If (reader.Name = "ColumnIndex") Then
ReportElement.ColumnIndex = reader.ReadElementString()
End If
If (reader.Name = "ControlType") Then
ReportElement.ControlType = reader.ReadElementString()
End If
If (reader.Name = "Values") Then
ReportElement.AddValue (0, reader.ReadElementString())
End If
case XmlNodeType.EndElement
If (reader.Name = "LookUp") then
al.Add(ReportElement)
ReportElement.Reset()
End If
End Select
End While

I've tried a few different things to get the Values elements such as:
reader.GetAttribute("BookMark")
But it returns "Nothing" in the Command window.
Could someone please let me know how to get the values element. Thanks
Michael

Nov 12 '05 #2
Thanks for the quick reply. I have another question for you. Do the elements
in the Lookup section always have to be the same. The reason I asked, is that
I originally had a Lookup section that did not have the Values elements at
the start of the file, and when it got to the loopup that had the Values
elements it never showed the Values element. I setup a file with 2 Lockups in
it with all the elements and it sees the Values element (but not with the
Attribute Type). It sees it as a regular Element type, but I can't get at the
data.
I tried your suggestiont, but it never gets to the Attributes section. I
added the following case to the original case statment:
case xmlnodetype.Attribute
If (reader.Name = "Values") Then
ReportElement.AddValue (0, reader.ReadElementString())
End If
I can use Altova XMLSpy and can see all the elements including the Values
elements. Have any suggestions. Thanks
Michael


"Alex Passos" wrote:
I think those nodes would be of type attribute. Put in a case statement to
handle this type in your code.

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...
Hi All,
I need a few suggestions. I have the following XML segment:
<LookUp>
<ControlType>CheckBoxGroup</ControlType>
<DBField>LastMedDate</DBField>
<ControlName>cmbGoal1</ControlName>
<Values VALUE="0" BookMark="Goal1Progress"/>
<Values VALUE="1" BookMark="Goal1NoProgress"/>
<Values VALUE="2" BookMark="Goal1NA"/>
</LookUp>
I have code that will read everything except the "Values" elements. Here
is
the code:
While reader.Read()
Select Case (reader.NodeType)
Case XmlNodeType.Element
If (reader.Name = "DBField") Then
ReportElement.DBField() = reader.ReadElementString()
End If
If (reader.Name = "BookMark") Then
ReportElement.BookMark = reader.ReadElementString()
End If
If (reader.Name = "ControlName") Then
ReportElement.ControlName = reader.ReadElementString()
End If
If (reader.Name = "ColumnIndex") Then
ReportElement.ColumnIndex = reader.ReadElementString()
End If
If (reader.Name = "ControlType") Then
ReportElement.ControlType = reader.ReadElementString()
End If
If (reader.Name = "Values") Then
ReportElement.AddValue (0, reader.ReadElementString())
End If
case XmlNodeType.EndElement
If (reader.Name = "LookUp") then
al.Add(ReportElement)
ReportElement.Reset()
End If
End Select
End While

I've tried a few different things to get the Values elements such as:
reader.GetAttribute("BookMark")
But it returns "Nothing" in the Command window.
Could someone please let me know how to get the values element. Thanks
Michael


Nov 12 '05 #3
Generally you would want the elements in a hiearchy to be the same because
XML is a data description language, for the purpose of transmitting data
between consumers and producers of data in a universal format. Most times
you will see XML being exported from database systems that describe exactly
tables, rows, and columns; if for example one row contains an extra column
then your database table isn't really a table anymore is it? However if you
have data in "columns" that are "NULL" or empty you can just write out the
tag with empty like:

<somecolumn/>

And it will parse correctly back into a consumer that expects that column,
the value will be "empty".

Alex
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
Thanks for the quick reply. I have another question for you. Do the
elements
in the Lookup section always have to be the same. The reason I asked, is
that
I originally had a Lookup section that did not have the Values elements at
the start of the file, and when it got to the loopup that had the Values
elements it never showed the Values element. I setup a file with 2 Lockups
in
it with all the elements and it sees the Values element (but not with the
Attribute Type). It sees it as a regular Element type, but I can't get at
the
data.
I tried your suggestiont, but it never gets to the Attributes section. I
added the following case to the original case statment:
case xmlnodetype.Attribute
If (reader.Name = "Values") Then
ReportElement.AddValue (0, reader.ReadElementString())
End If
I can use Altova XMLSpy and can see all the elements including the Values
elements. Have any suggestions. Thanks
Michael


"Alex Passos" wrote:
I think those nodes would be of type attribute. Put in a case statement
to
handle this type in your code.

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...
> Hi All,
> I need a few suggestions. I have the following XML segment:
> <LookUp>
> <ControlType>CheckBoxGroup</ControlType>
> <DBField>LastMedDate</DBField>
> <ControlName>cmbGoal1</ControlName>
> <Values VALUE="0" BookMark="Goal1Progress"/>
> <Values VALUE="1" BookMark="Goal1NoProgress"/>
> <Values VALUE="2" BookMark="Goal1NA"/>
> </LookUp>
> I have code that will read everything except the "Values" elements.
> Here
> is
> the code:
> While reader.Read()
> Select Case (reader.NodeType)
> Case XmlNodeType.Element
> If (reader.Name = "DBField") Then
> ReportElement.DBField() = reader.ReadElementString()
> End If
> If (reader.Name = "BookMark") Then
> ReportElement.BookMark = reader.ReadElementString()
> End If
> If (reader.Name = "ControlName") Then
> ReportElement.ControlName = reader.ReadElementString()
> End If
> If (reader.Name = "ColumnIndex") Then
> ReportElement.ColumnIndex = reader.ReadElementString()
> End If
> If (reader.Name = "ControlType") Then
> ReportElement.ControlType = reader.ReadElementString()
> End If
> If (reader.Name = "Values") Then
> ReportElement.AddValue (0, reader.ReadElementString())
> End If
> case XmlNodeType.EndElement
> If (reader.Name = "LookUp") then
> al.Add(ReportElement)
> ReportElement.Reset()
> End If
> End Select
> End While
>
> I've tried a few different things to get the Values elements such as:
> reader.GetAttribute("BookMark")
> But it returns "Nothing" in the Command window.
> Could someone please let me know how to get the values element. Thanks
> Michael
>


Nov 12 '05 #4
Hi Alex,
Thanks again for the quick reply. That will work for me, I can make sure it
stays the same for all the lookups. As a test I did setup the file that
contains two lookups, but I still could not get at the values as described
before. Have any idea what is happening. I found in the docs that
"An Attribute node can have the following child node types: Text and
EntityReference. The Attribute node does not appear as the child node of any
other node type. It is not considered a child node of an Element."
I was wondering if this is the reason I could not see the data. Have any
suggestions. Thanks so much for the help so far.
Thanks
Michael

"Alex Passos" wrote:
Generally you would want the elements in a hiearchy to be the same because
XML is a data description language, for the purpose of transmitting data
between consumers and producers of data in a universal format. Most times
you will see XML being exported from database systems that describe exactly
tables, rows, and columns; if for example one row contains an extra column
then your database table isn't really a table anymore is it? However if you
have data in "columns" that are "NULL" or empty you can just write out the
tag with empty like:

<somecolumn/>

And it will parse correctly back into a consumer that expects that column,
the value will be "empty".

Alex
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
Thanks for the quick reply. I have another question for you. Do the
elements
in the Lookup section always have to be the same. The reason I asked, is
that
I originally had a Lookup section that did not have the Values elements at
the start of the file, and when it got to the loopup that had the Values
elements it never showed the Values element. I setup a file with 2 Lockups
in
it with all the elements and it sees the Values element (but not with the
Attribute Type). It sees it as a regular Element type, but I can't get at
the
data.
I tried your suggestiont, but it never gets to the Attributes section. I
added the following case to the original case statment:
case xmlnodetype.Attribute
If (reader.Name = "Values") Then
ReportElement.AddValue (0, reader.ReadElementString())
End If
I can use Altova XMLSpy and can see all the elements including the Values
elements. Have any suggestions. Thanks
Michael


"Alex Passos" wrote:
I think those nodes would be of type attribute. Put in a case statement
to
handle this type in your code.

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...
> Hi All,
> I need a few suggestions. I have the following XML segment:
> <LookUp>
> <ControlType>CheckBoxGroup</ControlType>
> <DBField>LastMedDate</DBField>
> <ControlName>cmbGoal1</ControlName>
> <Values VALUE="0" BookMark="Goal1Progress"/>
> <Values VALUE="1" BookMark="Goal1NoProgress"/>
> <Values VALUE="2" BookMark="Goal1NA"/>
> </LookUp>
> I have code that will read everything except the "Values" elements.
> Here
> is
> the code:
> While reader.Read()
> Select Case (reader.NodeType)
> Case XmlNodeType.Element
> If (reader.Name = "DBField") Then
> ReportElement.DBField() = reader.ReadElementString()
> End If
> If (reader.Name = "BookMark") Then
> ReportElement.BookMark = reader.ReadElementString()
> End If
> If (reader.Name = "ControlName") Then
> ReportElement.ControlName = reader.ReadElementString()
> End If
> If (reader.Name = "ColumnIndex") Then
> ReportElement.ColumnIndex = reader.ReadElementString()
> End If
> If (reader.Name = "ControlType") Then
> ReportElement.ControlType = reader.ReadElementString()
> End If
> If (reader.Name = "Values") Then
> ReportElement.AddValue (0, reader.ReadElementString())
> End If
> case XmlNodeType.EndElement
> If (reader.Name = "LookUp") then
> al.Add(ReportElement)
> ReportElement.Reset()
> End If
> End Select
> End While
>
> I've tried a few different things to get the Values elements such as:
> reader.GetAttribute("BookMark")
> But it returns "Nothing" in the Command window.
> Could someone please let me know how to get the values element. Thanks
> Michael
>


Nov 12 '05 #5
Michael, take a look at this short article, it might help you some:

http://www.developer.com/net/csharp/article.php/3489611

Alex

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
Hi Alex,
Thanks again for the quick reply. That will work for me, I can make sure
it
stays the same for all the lookups. As a test I did setup the file that
contains two lookups, but I still could not get at the values as described
before. Have any idea what is happening. I found in the docs that
"An Attribute node can have the following child node types: Text and
EntityReference. The Attribute node does not appear as the child node of
any
other node type. It is not considered a child node of an Element."
I was wondering if this is the reason I could not see the data. Have any
suggestions. Thanks so much for the help so far.
Thanks
Michael

"Alex Passos" wrote:
Generally you would want the elements in a hiearchy to be the same
because
XML is a data description language, for the purpose of transmitting data
between consumers and producers of data in a universal format. Most
times
you will see XML being exported from database systems that describe
exactly
tables, rows, and columns; if for example one row contains an extra
column
then your database table isn't really a table anymore is it? However if
you
have data in "columns" that are "NULL" or empty you can just write out
the
tag with empty like:

<somecolumn/>

And it will parse correctly back into a consumer that expects that
column,
the value will be "empty".

Alex
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
> Thanks for the quick reply. I have another question for you. Do the
> elements
> in the Lookup section always have to be the same. The reason I asked,
> is
> that
> I originally had a Lookup section that did not have the Values elements
> at
> the start of the file, and when it got to the loopup that had the
> Values
> elements it never showed the Values element. I setup a file with 2
> Lockups
> in
> it with all the elements and it sees the Values element (but not with
> the
> Attribute Type). It sees it as a regular Element type, but I can't get
> at
> the
> data.
> I tried your suggestiont, but it never gets to the Attributes section.
> I
> added the following case to the original case statment:
> case xmlnodetype.Attribute
> If (reader.Name = "Values") Then
> ReportElement.AddValue (0, reader.ReadElementString())
> End If
> I can use Altova XMLSpy and can see all the elements including the
> Values
> elements. Have any suggestions. Thanks
> Michael
>
>
>
>
> "Alex Passos" wrote:
>
>> I think those nodes would be of type attribute. Put in a case
>> statement
>> to
>> handle this type in your code.
>>
>> "Michael" <Mi*****@discussions.microsoft.com> wrote in message
>> news:8C**********************************@microsof t.com...
>> > Hi All,
>> > I need a few suggestions. I have the following XML segment:
>> > <LookUp>
>> > <ControlType>CheckBoxGroup</ControlType>
>> > <DBField>LastMedDate</DBField>
>> > <ControlName>cmbGoal1</ControlName>
>> > <Values VALUE="0" BookMark="Goal1Progress"/>
>> > <Values VALUE="1" BookMark="Goal1NoProgress"/>
>> > <Values VALUE="2" BookMark="Goal1NA"/>
>> > </LookUp>
>> > I have code that will read everything except the "Values" elements.
>> > Here
>> > is
>> > the code:
>> > While reader.Read()
>> > Select Case (reader.NodeType)
>> > Case XmlNodeType.Element
>> > If (reader.Name = "DBField") Then
>> > ReportElement.DBField() = reader.ReadElementString()
>> > End If
>> > If (reader.Name = "BookMark") Then
>> > ReportElement.BookMark = reader.ReadElementString()
>> > End If
>> > If (reader.Name = "ControlName") Then
>> > ReportElement.ControlName = reader.ReadElementString()
>> > End If
>> > If (reader.Name = "ColumnIndex") Then
>> > ReportElement.ColumnIndex = reader.ReadElementString()
>> > End If
>> > If (reader.Name = "ControlType") Then
>> > ReportElement.ControlType = reader.ReadElementString()
>> > End If
>> > If (reader.Name = "Values") Then
>> > ReportElement.AddValue (0, reader.ReadElementString())
>> > End If
>> > case XmlNodeType.EndElement
>> > If (reader.Name = "LookUp") then
>> > al.Add(ReportElement)
>> > ReportElement.Reset()
>> > End If
>> > End Select
>> > End While
>> >
>> > I've tried a few different things to get the Values elements such
>> > as:
>> > reader.GetAttribute("BookMark")
>> > But it returns "Nothing" in the Command window.
>> > Could someone please let me know how to get the values element.
>> > Thanks
>> > Michael
>> >
>>
>>
>>


Nov 12 '05 #6
Hi Alex,
Thanks for all the help. In a book I just got (Programming Microsoft Visual
Basic .NET) I found the answer. The Values element will be found under the
Element Nodetype, but I had to use the MoveToNextAttribute function to move
to the Attribute. I included a section of the Case statement.

If (reader.Name = "Values") Then
dim isValueAdded as Boolean = False
if reader.HasAttributes then
Do while reader.MoveToNextAttribute ()
if Reader.Name = "VALUE" then
lValue = Reader.Value
End If
if Reader.Name = "BookMark" then
lBookmark = Reader.Value
isValueAdded = True
End If
Loop
End If
if isValueAdded = True then
ReportElement.AddValue (lValue, lBookmark)
end if
Thanks again for all the help.
Michael
"Alex Passos" wrote:
Michael, take a look at this short article, it might help you some:

http://www.developer.com/net/csharp/article.php/3489611

Alex

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
Hi Alex,
Thanks again for the quick reply. That will work for me, I can make sure
it
stays the same for all the lookups. As a test I did setup the file that
contains two lookups, but I still could not get at the values as described
before. Have any idea what is happening. I found in the docs that
"An Attribute node can have the following child node types: Text and
EntityReference. The Attribute node does not appear as the child node of
any
other node type. It is not considered a child node of an Element."
I was wondering if this is the reason I could not see the data. Have any
suggestions. Thanks so much for the help so far.
Thanks
Michael

"Alex Passos" wrote:
Generally you would want the elements in a hiearchy to be the same
because
XML is a data description language, for the purpose of transmitting data
between consumers and producers of data in a universal format. Most
times
you will see XML being exported from database systems that describe
exactly
tables, rows, and columns; if for example one row contains an extra
column
then your database table isn't really a table anymore is it? However if
you
have data in "columns" that are "NULL" or empty you can just write out
the
tag with empty like:

<somecolumn/>

And it will parse correctly back into a consumer that expects that
column,
the value will be "empty".

Alex
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
> Thanks for the quick reply. I have another question for you. Do the
> elements
> in the Lookup section always have to be the same. The reason I asked,
> is
> that
> I originally had a Lookup section that did not have the Values elements
> at
> the start of the file, and when it got to the loopup that had the
> Values
> elements it never showed the Values element. I setup a file with 2
> Lockups
> in
> it with all the elements and it sees the Values element (but not with
> the
> Attribute Type). It sees it as a regular Element type, but I can't get
> at
> the
> data.
> I tried your suggestiont, but it never gets to the Attributes section.
> I
> added the following case to the original case statment:
> case xmlnodetype.Attribute
> If (reader.Name = "Values") Then
> ReportElement.AddValue (0, reader.ReadElementString())
> End If
> I can use Altova XMLSpy and can see all the elements including the
> Values
> elements. Have any suggestions. Thanks
> Michael
>
>
>
>
> "Alex Passos" wrote:
>
>> I think those nodes would be of type attribute. Put in a case
>> statement
>> to
>> handle this type in your code.
>>
>> "Michael" <Mi*****@discussions.microsoft.com> wrote in message
>> news:8C**********************************@microsof t.com...
>> > Hi All,
>> > I need a few suggestions. I have the following XML segment:
>> > <LookUp>
>> > <ControlType>CheckBoxGroup</ControlType>
>> > <DBField>LastMedDate</DBField>
>> > <ControlName>cmbGoal1</ControlName>
>> > <Values VALUE="0" BookMark="Goal1Progress"/>
>> > <Values VALUE="1" BookMark="Goal1NoProgress"/>
>> > <Values VALUE="2" BookMark="Goal1NA"/>
>> > </LookUp>
>> > I have code that will read everything except the "Values" elements.
>> > Here
>> > is
>> > the code:
>> > While reader.Read()
>> > Select Case (reader.NodeType)
>> > Case XmlNodeType.Element
>> > If (reader.Name = "DBField") Then
>> > ReportElement.DBField() = reader.ReadElementString()
>> > End If
>> > If (reader.Name = "BookMark") Then
>> > ReportElement.BookMark = reader.ReadElementString()
>> > End If
>> > If (reader.Name = "ControlName") Then
>> > ReportElement.ControlName = reader.ReadElementString()
>> > End If
>> > If (reader.Name = "ColumnIndex") Then
>> > ReportElement.ColumnIndex = reader.ReadElementString()
>> > End If
>> > If (reader.Name = "ControlType") Then
>> > ReportElement.ControlType = reader.ReadElementString()
>> > End If
>> > If (reader.Name = "Values") Then
>> > ReportElement.AddValue (0, reader.ReadElementString())
>> > End If
>> > case XmlNodeType.EndElement
>> > If (reader.Name = "LookUp") then
>> > al.Add(ReportElement)
>> > ReportElement.Reset()
>> > End If
>> > End Select
>> > End While
>> >
>> > I've tried a few different things to get the Values elements such
>> > as:
>> > reader.GetAttribute("BookMark")
>> > But it returns "Nothing" in the Command window.
>> > Could someone please let me know how to get the values element.
>> > Thanks
>> > Michael
>> >
>>
>>
>>


Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by CGuy | last post: by
2 posts views Thread by | last post: by
11 posts views Thread by Ben | last post: by
6 posts views Thread by Developer | last post: by
3 posts views Thread by Michael Malinak | last post: by
3 posts views Thread by Gary Stephenson | last post: by

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.