[ASP.Net] XML uitlezen

Pagina: 1
Acties:

  • NLAnaconda
  • Registratie: Januari 2007
  • Laatst online: 03-07 12:42
Beste tweakers.

Sinds een poosje ben ik aan het knooien met asp.net (vb)
Nu wil ik een via een url een locatie id van weather.com opvragen.

http://xoap.weather.com/search/search?where=atlanta

Deze geeft een response terug in XML vorm:

<search ver="2.0">
<loc id="USGA0028" type="1">Atlanta, GA</loc>
</search>

Nou gebruik ik de volgende code om de gegevens op het scherm te spuwen:

<asp:RadioButtonList ID="RadioButtonList1" runat="server" DataSourceID="Weer" DataTextField="id" DataValueField="id">
</asp:RadioButtonList><asp:XmlDataSource ID="Weer" runat="server" DataFile="http://xoap.weather.com/search/search?where=atlanta">
</asp:XmlDataSource>


Met de DataTextField="id" krijg ik netjes de waarde "USGA0028"
Maar met welke naam roep ik nu de plaatsnaam "Atlanta, GA" op...
Ik dacht aan loc, omdat het tussen die tags staat. Maar helaas dat wil nie.

Kan iemand mij helpen ?

  • BM
  • Registratie: September 2001
  • Laatst online: 14:28

BM

Moderator Spielerij
Misschien dat je innerText kunt gebruiken als property, maar het lijkt mij persoonlijk handiger als je er een defelijke XML parser overheen gooit. Helaas kan ik je daar niet mee helpen, daar heb ik geen ervaring mee :)

Xbox
Even the dark has a silver lining | I'm all you can imagine times infinity, times three


  • NLAnaconda
  • Registratie: Januari 2007
  • Laatst online: 03-07 12:42
Bedankt.. innerText werkt niet... degelijke XML Parser....
Is even kijken of ik daar wat tutorials over kan vinden...

Verwijderd

De handigste manier bij .NET / VS2005 is een web reference toevoegen, of als dat niet kan een WSDL implementeren. Maar die xoap.weather.com/search/search link gaf me steeds een "This document is intended only for use by authorized licensees of The Weather Channel" melding, en daar kan ik niet zoveel mee.

Bottom line: wanneer je in VS een web reference kunt toevoegen, hoef je je nauwelijks te bekommeren over de onderliggende XML maar wordt een proxy voor je aangemaakt die de XML serialisatie voor je doet en de boel netjes in objecten duwt.

  • NLAnaconda
  • Registratie: Januari 2007
  • Laatst online: 03-07 12:42
Oh excuses voor die licensees error.. dit komt eruit:


<?xml version="1.0" encoding="ISO-8859-1" ?>
- <!-- This document is intended only for use by authorized licensees of The Weather Channel. Unauthorized use is prohibited. Copyright 1995-2005, The Weather Channel Interactive, Inc. All Rights Reserved.
-->
- <search ver="2.0">
<loc id="USGA0028" type="1">Atlanta, GA</loc>
<loc id="USGA0029" type="1">Atlanta/Fulton County Arpt, GA</loc>
<loc id="USID0011" type="1">Atlanta, ID</loc>
<loc id="USIL0057" type="1">Atlanta, IL</loc>
<loc id="USIN0019" type="1">Atlanta, IN</loc>
<loc id="USKS0030" type="1">Atlanta, KS</loc>
<loc id="USLA0022" type="1">Atlanta, LA</loc>
<loc id="USMI0036" type="1">Atlanta, MI</loc>
<loc id="USMO0037" type="1">Atlanta, MO</loc>
<loc id="USNE0027" type="1">Atlanta, NE</loc>
<loc id="USNY0063" type="1">Atlanta, NY</loc>
<loc id="USTX0055" type="1">Atlanta, TX</loc>
</search>

Maar ik ga me eens verdiepen in die xml serialisatie.. bedankt voor de tips!

Verwijderd

Die XML kreeg ik ook, incl. licensees melding.
Maar op 't moment dat ik een "dit is niet voor jou bedoeld" melding tegenkom, ga ik niet verder.

Misschien ben ik roomser dan de paus, maar ik probeer niet aan software of content te komen waar ik geen recht op heb. Ik verdien m'n boterham met het maken van software, en dat gun ik m'n collega ontwikkelaars ook.

  • NLAnaconda
  • Registratie: Januari 2007
  • Laatst online: 03-07 12:42
Ja ben het helemaal mee eens, maar je kan een gratis licentie krijgen door je te registreren.
Je applicatie moet alleen aan een paar bepaalde voorwaarden voldoen. (linkje naar weather.com. minder dan 25.000 request per maand enz enz)
Niet dat je denk dat ik illegaal bezig ben ;)

Meer info: Weather XML Data Feed Registration
https://registration.weather.com/ursa/xmloap/step1?

  • TeeDee
  • Registratie: Februari 2001
  • Laatst online: 14:04

TeeDee

CQB 241

Je zou met Xpath / Xquery je waardes uit kunnen lezen.

Bijvoorbeeld: http://www.aspfree.com/c/...g-with-XPath-The-NET-Way/

[ Voor 42% gewijzigd door TeeDee op 07-02-2007 08:58 ]

Heart..pumps blood.Has nothing to do with emotion! Bored


  • NLAnaconda
  • Registratie: Januari 2007
  • Laatst online: 03-07 12:42
Die web reference wil niet lukken. Telkens als ik de URL ingeef krijg ik dit verhaal:

The document at the url http://xoap.weather.com/search/search?where=atlanta was not recognized as a known document type.
The error message from each known type may help you fix the problem:

- Report from 'DISCO Document' is 'Discovery document at the URL http://xoap.weather.com/search/search?where=atlanta could not be found.'.

- The document format is not recognized (the content type is 'text/plain;charset=ISO-8859-1').

- Report from 'WSDL Document' is 'There is an error in XML document (3, 2).'.

- <search xmlns=''> was not expected.

- Report from 'XML Schema' is 'The root element of a W3C XML Schema should be <schema> and its namespace should be 'http://www.w3.org/2001/XMLSchema'.'.

  • NLAnaconda
  • Registratie: Januari 2007
  • Laatst online: 03-07 12:42
Nou tis dan einelijk gelukt...

Mocht ooit iemand dit topic tegenkomen tijdens het zoeken:


Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
        Dim m_xmld As XmlDocument
        Dim m_nodelist As XmlNodeList
        Dim m_node As XmlNode
        'Create the XML Document
        m_xmld = New XmlDocument()
        'Load the Xml file
        m_xmld.Load("http://xoap.weather.com/search/search?where=" & searchstring)
        'Get the list of name nodes 
        m_nodelist = m_xmld.SelectNodes("/search/loc")
        'Loop through the nodes
        For Each m_node In m_nodelist
            'Get the Gender Attribute Value
            Dim id = m_node.Attributes.GetNamedItem("id").Value
            'Get the firstName Element Value
            Dim plaats = m_node.ChildNodes.Item(0).InnerText
            'Get the lastName Element Value
            landList.Items.Add(New ListItem(plaats, id))
        Next
Pagina: 1