3

xml応答を受信して​​いるので、これを解析したいと思います。

現在、XML応答を受信する必要があるのは次のとおりです。

    Dim textReader = New IO.StreamReader(Request.InputStream)

    Request.InputStream.Seek(0, IO.SeekOrigin.Begin)
    textReader.DiscardBufferedData()

    Dim Xmlin = XDocument.Load(textReader)

どうすればこれを処理して要素値を選択できますか?

<subscription>
<reference>abc123</reference>
<status>active</status>
<customer>
    <fname>Joe</fname>
    <lname>bloggs</lname>
    <company>Bloggs inc</company>
    <phone>1234567890</phone>
    <email>joebloggs@hotmail.com</email>
 </customer>
 </subscription>

文字列形式の場合は、次を使用してこれを行うことができます

    Dim xmlE As XElement = XElement.Parse(strXML) ' strXML is string version of XML

    Dim strRef As String = xmlE.Element("reference")

request.inputstreamをstrign形式に変換する必要がありますか、それとも別のより良い方法がありますか?

ありがとう

4

2 に答える 2

1

request.inputstreamをstrign形式に変換する必要がありますか、それとも別のより良い方法がありますか?

リクエストストリームから直接ロードできます。文字列に変換する必要はありません。

Request.InputStream.Position = 0
Dim Xmlin = XDocument.Load(Request.InputStream)
Dim reference = Xmlin.Element("subscription").Element("reference").Value

また:

Dim reference = Xmlin.Descendants("reference").First().Value
于 2012-06-19T12:01:01.407 に答える
1

結局、多くのテストの後、私はこれを機能させることしかできませんでした:

    Dim textReader = New IO.StreamReader(Request.InputStream)

    Request.InputStream.Seek(0, IO.SeekOrigin.Begin)
    textReader.DiscardBufferedData()

    Dim Xmlin = XDocument.Load(textReader)

    Dim strXml As String = Xmlin.ToString

    Dim xmlE As XElement = XElement.Parse(strXml)
    Dim strRef As String = xmlE.Element("reference")
    Dim strStatus As String = xmlE.Element("status")
    Dim strFname As String = xmlE.Element("customer").Element("fname").Value()
    Dim strLname As String = xmlE.Element("customer").Element("lname").Value()
    Dim strCompany As String = xmlE.Element("customer").Element("company").Value()
    Dim strPhone As String = xmlE.Element("customer").Element("phone").Value()
    Dim strEmail As String = xmlE.Element("customer").Element("email").Value()
于 2012-06-24T13:50:22.070 に答える