SAOP通信にて得たxmlがうまくパースできません
ruby
1@doc = Nokogiri::XML(response.body) 2puts @doc
以下レスポンスxmlです。
xml
1<?xml version="1.0" encoding="UTF-8"?> 2<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 3 <S:Body> 4 <ELtest xmlns="http://www.xxx.com" xmlns:ns2="http://www.xxx.com" Version="1.0"> 5 <Success/> 6 <eltests> 7 <eltest> 8 <Date End="2017-10-11" Start="2017-10-01" Status="Close"/> 9 <Date End="2017-10-15" Start="2017-10-12" Status="Open"/> 10 <Date End="2017-10-16" Start="2017-10-16" Status="Close"/> 11 <Date End="2017-10-20" Start="2017-10-17" Status="Open"/> 12 <Price total="4000" End="2017-10-12" Start="2017-10-12"/> 13 <Price total="6000" End="2017-10-13" Start="2017-10-13"/> 14 <Price total="6000" End="2017-10-14" Start="2017-10-14"/> 15 <Price total="4000" End="2017-10-15" Start="2017-10-15"/> 16 <Price total="4000" End="2017-10-17" Start="2017-10-17"/> 17 <Price total="4000" End="2017-10-18" Start="2017-10-18"/> 18 <Price total="4000" End="2017-10-19" Start="2017-10-19"/> 19 <Price total="6000" End="2017-10-20" Start="2017-10-20"/> 20 </eltest> 21 </eltests> 22 </ELtest> 23 </S:Body> 24</S:Envelope>
このDate EndやPrice totalの値をxpathで取得しようとしてもうまくいきません。
以下のように指定すると
ruby
1puts @doc.xpath("//S:Body")[0].children[0].children[1].children[0]
レスポンス
xml
1<eltests> 2 <eltest> 3 <Date End="2017-10-11" Start="2017-10-01" Status="Close"/> 4 <Date End="2017-10-15" Start="2017-10-12" Status="Open"/> 5 <Date End="2017-10-16" Start="2017-10-16" Status="Close"/> 6 <Date End="2017-10-20" Start="2017-10-17" Status="Open"/> 7 <Price total="4000" End="2017-10-12" Start="2017-10-12"/> 8 <Price total="6000" End="2017-10-13" Start="2017-10-13"/> 9 <Price total="6000" End="2017-10-14" Start="2017-10-14"/> 10 <Price total="4000" End="2017-10-15" Start="2017-10-15"/> 11 <Price total="4000" End="2017-10-17" Start="2017-10-17"/> 12 <Price total="4000" End="2017-10-18" Start="2017-10-18"/> 13 <Price total="4000" End="2017-10-19" Start="2017-10-19"/> 14 <Price total="6000" End="2017-10-20" Start="2017-10-20"/> 15 </eltest> 16 </eltests>
上記のようなところまでは絞りこめるのですが、
欲しいデータ部分にたどり着きません。
どなたかパースのやり方わかりますでしょうか?
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。