Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Parsing question

Status
Not open for further replies.

Dashley

Programmer
Dec 5, 2002
925
US
Hi, I've just started using XML. I have the following code that works against the following xml file.

Code:
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Table1>
    <Location>Office</Location>
    </Table1>
  <Table1>
  <Table1>
    <DCurrID>15991</DCurrID>
    <DValue>1</DValue>
  </Table1>
  <Table1>
    <DCurrID>15991</DCurrID>
    <DValue>2</DValue>
  </Table1>
  <Table1>
    <DCurrID>15992</DCurrID>
    <DValue>3</DValue>
  </Table1>
  <Table1>
    <DCurrID>15993</DCurrID>
    <DValue>6.45</DValue>
  </Table1>
 </NewDataSet>


Code:
Private Sub read_XML()

Try
Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlNode
m_xmld = New XmlDocument
m_xmld.Load("C:\myXmlDoc.xml")
m_nodelist = m_xmld.SelectNodes("/NewDataSet/Table1")

For Each m_node In m_nodelist

Dim curridvalue = m_node.ChildNodes.Item(0).InnerText
Dim dvalue= m_node.ChildNodes.Item(1).InnerText
ListView1.Items.Add(curridvalue & " " & dvalue)
ListView1.Columns.Add("Col1", 500, HorizontalAlignment.Center)
ListView1.View = View.Details

Next
Catch errorVariable As Exception
Console.Write(errorVariable.ToString())
        End Try
    End Sub


My problrm is I can not read or get to the <location> value "Office" . The rest of the data (DCurrID and Dvalue) can be read out of the file and populate the listview as needed.

Any Ideas on how I can read the value fo <Location>

Thanks

Dan
 
Hi dashley,
i m not test ur code but if it's ur real xml document ,here is the mistake...

Code:
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Table1>
    <Location>Office</Location>
    </Table1>
[red]<Table1>[/red]    [b]is it true?[/b]
  <Table1>
    <DCurrID>15991</DCurrID>
    <DValue>1</DValue>
  </Table1>
  <Table1>
    <DCurrID>15991</DCurrID>
    <DValue>2</DValue>
  </Table1>
  <Table1>
    <DCurrID>15992</DCurrID>
    <DValue>3</DValue>
  </Table1>
  <Table1>
    <DCurrID>15993</DCurrID>
    <DValue>6.45</DValue>
  </Table1>
 </NewDataSet>

i hope it helps...
 
Daniel,

Opps I must have missed that when I pasted the xml into the code frame.

The actual xml file reads like this.
Code:
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Table1>
    <Location>Office</Location>
  </Table1>
  <Table1>
    <DCurrID>15991</DCurrID>
    <DValue>2</DValue>
  </Table1>
  <Table1>
    <DCurrID>15992</DCurrID>
    <DValue>3</DValue>
  </Table1>
  <Table1>
    <DCurrID>15993</DCurrID>
    <DValue>6.45</DValue>
  </Table1>
 </NewDataSet>

If I remove:

Code:
  <Table1>
    <Location>Office</Location>
  </Table1>

everything works. When I put it back in I get nothing

Thanks


Dan
 
Daniel,

I finally figured it out. If I add another row of data to my dataset which makes another childnode to the location it works fine.

<Table1>
<Location>Location</Location>
<LValue>Office</LValue>
</Table1>


Thanks

Dan
 
Rick,

Hi how are ya. I'll take a look at it. Im working with with the Compact Framework so I have to watch what I use.

Thanks


Dan
 
If you're working with CF, I would suggest you develop in that first, then if you are going to do a desktop version it's easy enough to migrate that way. Can be much harder to do the reverse.

Dale
 
Thanks Dale. I already learned that the hard way (HA) much to my supprise.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top