2017-07-01 8 views
0

私は原子フィード/ xmlファイルからいくつかの行を取得し、データベースに入れたいと思います。私はデータベースに文字列を入力する方法を知っていますが、私はこれが初めてであるので、XMLファイルで作業する方法を理解するのには苦労しています。 は、xmlファイルは "C:\ feed.xml" と言うことができますし、このようになります。.. database.insertの一部を心配しないでくださいvb.net xml atom feed属性を取得

<?xml version="1.0" encoding="utf-8" ?> 
<feed xmlns="http://www.w3.org/2005/Atom"> 
    <title>This is the Title</title> 
    <link href="https://www.website.com"></link> 
    <entry> 
    <title>Title 1</title> 
    <link href="http://www.website.com/Title/page1"></link> 
    </entry> 
    <entry> 
    <title>Title 2</title> 
    <link href="http://www.website.com/Title/page2"></link> 
    </entry> 
</feed> 

擬似コード...

Dim doc As XDocument = XDocument.Load("C:\feed.xml") 

For i = 0 to entry.count - 1 
    Dim String1 as String = title(i).InnerText 
    Dim String2 as String = link href(i).InnerText 
    database.insert(String1, String2) 
Next i 

、私はそれを行う方法を知っている、私はちょうどString1とString2を取得するのに役立つ必要があります。具体的にString2私はちょうどString2 = "http // www.website.com /タイトル/ページ1"(注:目的には不足しています)

私はそれが必要なので、ありがとう。

+0

(.aspxのhttps://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.syndicationfeed(V = vs.110))[SyndicationFeed]を参照されたいです。 –

答えて

0

はあなたがSyndicationFeedクラスを使用することができ、次のXML LINQ

Imports System.Xml 
Imports System.Xml.Linq 
Module Module1 

    Const FILENAME As String = "c:\temp\test.xml" 
    Sub Main() 
     Dim doc As XDocument = XDocument.Load(FILENAME) 
     Dim feed As XElement = doc.Root 
     Dim ns As XNamespace = feed.GetDefaultNamespace() 

     Dim results = doc.Elements(ns + "feed").Select(Function(x) New With { _ 
                 .title = CType(x.Element(ns + "title"), String), _ 
                 .link = CType(x.Element(ns + "link").Attribute("href"), String), _ 
                 .entry = x.Elements(ns + "entry").Select(Function(y) New With { 
                           .title = CType(y.Element(ns + "title"), String), _ 
                           .link = CType(y.Element(ns + "link").Attribute("href"), String) _ 
                           }).ToList() 
                }).FirstOrDefault() 

    End Sub 

End Module 
0

を試してみてください。

System.ServiceModel.dllアセンブリへの参照を追加します。

Imports System.ServiceModel.Syndication 
Imports System.Xml 


Using xmlReader As XmlReader = XmlReader.Create("C:\feed.xml") 
    Dim feed As SyndicationFeed = SyndicationFeed.Load(xmlReader) 

    Console.WriteLine(feed.Title.Text) 

    For Each link In feed.Links 
     Console.WriteLine(link.Uri) 
    Next 

    For Each entry In feed.Items 
     Console.WriteLine(entry.Title.Text) 
     For Each link In entry.Links 
      Console.WriteLine(link.Uri) 
     Next 
    Next 
End Using 
関連する問題