Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. XML Interaction

XML Interaction

Scheduled Pinned Locked Moved Visual Basic
comxmljsonquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    The ANZAC
    wrote on last edited by
    #1

    Hello, I am trying to make a small app to interact with Tumblr.com. The API information page is here: http://www.tumblr.com/docs/api It outputs XML which i am not familiar with....yet. What i want to know is how would i tell a vb app to download this output and what sort of variable should i keep it in to work with? Is string appropriate? The ANZAC

    E 1 Reply Last reply
    0
    • T The ANZAC

      Hello, I am trying to make a small app to interact with Tumblr.com. The API information page is here: http://www.tumblr.com/docs/api It outputs XML which i am not familiar with....yet. What i want to know is how would i tell a vb app to download this output and what sort of variable should i keep it in to work with? Is string appropriate? The ANZAC

      E Offline
      E Offline
      Estys
      wrote on last edited by
      #2

      Imports System
      Imports System.IO
      Imports System.Net
      Imports System.Xml

      Module Module1
      Sub Main()
      'Address of URL, just a random user
      Dim URL As String = "http://harumacchi.tumblr.com/api/read"
      ' Get data
      Dim client As WebClient = New WebClient()

          ' Read an print to console
          Dim reader As StreamReader = New StreamReader(client.OpenRead(URL))
          Dim str As String = ""
      
          Do While reader.EndOfStream = False
              str = reader.ReadLine()
              Console.WriteLine(str)
              Console.ReadKey()
          Loop
      
          ' load as document
          Dim xmldoc As XmlDocument = New XmlDocument()
          xmldoc.Load(client.OpenRead(URL))
      
          For Each node As XmlNode In xmldoc.ChildNodes
      
              Console.WriteLine(node.Name)
              Console.ReadKey()
          Next
      
          ' read as xml
          Dim xmlreader As XmlTextReader = New XmlTextReader(client.OpenRead(URL))
      
          Do While xmlreader.Read()
      
              If xmlreader.NodeType = XmlNodeType.Element Then
                  Console.WriteLine(xmlreader.LocalName)
                  Console.ReadKey()
              End If
          Loop
      
      
      End Sub
      

      End Module

      I personally prefer XmlDocument but you could also use XmlTextReader.

      T 1 Reply Last reply
      0
      • E Estys

        Imports System
        Imports System.IO
        Imports System.Net
        Imports System.Xml

        Module Module1
        Sub Main()
        'Address of URL, just a random user
        Dim URL As String = "http://harumacchi.tumblr.com/api/read"
        ' Get data
        Dim client As WebClient = New WebClient()

            ' Read an print to console
            Dim reader As StreamReader = New StreamReader(client.OpenRead(URL))
            Dim str As String = ""
        
            Do While reader.EndOfStream = False
                str = reader.ReadLine()
                Console.WriteLine(str)
                Console.ReadKey()
            Loop
        
            ' load as document
            Dim xmldoc As XmlDocument = New XmlDocument()
            xmldoc.Load(client.OpenRead(URL))
        
            For Each node As XmlNode In xmldoc.ChildNodes
        
                Console.WriteLine(node.Name)
                Console.ReadKey()
            Next
        
            ' read as xml
            Dim xmlreader As XmlTextReader = New XmlTextReader(client.OpenRead(URL))
        
            Do While xmlreader.Read()
        
                If xmlreader.NodeType = XmlNodeType.Element Then
                    Console.WriteLine(xmlreader.LocalName)
                    Console.ReadKey()
                End If
            Loop
        
        
        End Sub
        

        End Module

        I personally prefer XmlDocument but you could also use XmlTextReader.

        T Offline
        T Offline
        The ANZAC
        wrote on last edited by
        #3

        Thanks. I'm not sure exactly how to work with this though. If you are willing to help more here I have further questions. Alternatively I can make a new thread. For instance, how would i then get certain bits of information about each post? I gather the For Each loop can be used to probe the nodes, but how would i find the id or link for each post using this loop?

        Please check out my articles: The ANZAC's articles

        E 1 Reply Last reply
        0
        • T The ANZAC

          Thanks. I'm not sure exactly how to work with this though. If you are willing to help more here I have further questions. Alternatively I can make a new thread. For instance, how would i then get certain bits of information about each post? I gather the For Each loop can be used to probe the nodes, but how would i find the id or link for each post using this loop?

          Please check out my articles: The ANZAC's articles

          E Offline
          E Offline
          Estys
          wrote on last edited by
          #4

          I'm a bit lost now. Don't you understand the tumbler/api xml or are you confused with the XmlDocument class?

          T 1 Reply Last reply
          0
          • E Estys

            I'm a bit lost now. Don't you understand the tumbler/api xml or are you confused with the XmlDocument class?

            T Offline
            T Offline
            The ANZAC
            wrote on last edited by
            #5

            I don't really understand how to use the xml document, how to look through the nodes etc and extract the information i want.

            Please check out my articles: The ANZAC's articles

            E 1 Reply Last reply
            0
            • T The ANZAC

              I don't really understand how to use the xml document, how to look through the nodes etc and extract the information i want.

              Please check out my articles: The ANZAC's articles

              E Offline
              E Offline
              Estys
              wrote on last edited by
              #6

              XML Specification In short, XML is a structured document, conforming to a schema. Unfortunatly tumblr does not provide this schema (an XSD). XmlDocument class When you load an XML document into an XmlDocument instance it creates an XmlNode for every tag encountered and adds it as a childnode to its parent. To traverse all nodes you start at the XmlDocument instance (it actually is an XmlNode itself!). The HasChildren property indicates whether the node has children, you can iterate over the ChildNodes collection to get the nodes (which can also have children themselve). A node also has an Attributes collection which contains things like name, ID, type etc. that you see in the tags of the XML file To find specific node(s) there are methods like SelectNodes and SelectSingleNode. These methods use XPath syntax. It's possible to generate a classmodel for use in your program. You need to locate XSD.exe, it's somewhere in "C:\Program Files\Microsoft SDKs\Windows\...\bin" This utily can generate an XSD schema from an XML file and a .vb classfile from the XSD. So capture the output from http://(USER).tumblr.com/api/read, save as xxxx.xml and feed the file to XSD.exe. Then feed xxxx.xsd to XSD.exe in add the resulting xxxx.vb to your project. Make sure that the captured XML contains all tags and attributes described on the tumblr/api page

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups