How can I get the value from the XML content below?
How to get the value of the title tag?
<?xml version="1.0" encoding=开发者_如何转开发"UTF-8"?>
<response status="ok" permission_level="admin" message="ready to use" cached="0">
<title>johndoe</title>
</response>
If the XML is in xml
then:
doc = Nokogiri::XML(xml)
jd = doc.at('title').text
The CSS style at
is probably the easiest approach for something like this. You could also use XPath if you prefer:
jd = doc.xpath('.//title').text
精彩评论