我想解析下面的XML来获取电子邮件地址。我可以得到messageid,但我认为有一个:在前面让我使用xpath。不知道如何提取电子邮件地址。我想试图解析与nokogiri和红宝石xml
xml.xpath( “// S:身体/发现/请求/ EmailAddress的”)。children.text.to_s
和
xml.xpath(“// S:身体/Discover/EmailAddress").children.text.to_s
如果我做xml.xpath(“// s:Body”)。children.text.to_s我得到的电子邮件和所有的新行和标签的版本但我不想解析电子邮件,如果我不必。
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">test url</a:Action>
<a:MessageID>mid</a:MessageID>
<a:ReplyTo>
<a:Address>test url</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">test url</a:To>
</s:Header>
<s:Body>
<Discover xmlns="test url">
<request xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<EmailAddress>[email protected]</EmailAddress>
<RequestVersion>1.0</RequestVersion>
</request>
</Discover>
</s:Body>
</s:Envelope>
https://amolnpujari.wordpress.com/2012/03/31/reading_huge_xml-rb我发现比引入nokogiri快牛的5倍,在牛,因此这里一个例子 - https://gist.github.com/amolpujari/5966431,搜索任何元素并以散列形式获取它 –