2012-03-28 2 views
0

나는 glowfoto API를 사용하고 있으며 XML 데이터를 구문 분석하려고합니다. 매우 간단하지만 작동시키지는 못합니다.rexml을 사용하여 루비에서 XML 데이터 구문 분석

<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<getserver>\n <uploadform>http://img5.glowfoto.com/uploadxml.php</uploadform>\n</getserver> 

가 어떻게 문자열로 URL이 REXML을 사용하는 것을 얻을 수 있습니다 :

는 XML 데이터입니다.

답변

4

REXML을 사용하면 다음과 같이 할 수 있습니다. REXML은 표준 라이브러리에 포함되어 있습니다

require 'rexml/document' 

xml = <<-XML 
<?xml version="1.0" encoding="utf-8"?> 
<getserver><uploadform>http://img5.glowfoto.com/uploadxml.php</uploadform></getserver> 
XML 

r = REXML::Document.new(xml) 
puts r.elements["getserver/uploadform"].first 
=> "http://img5.glowfoto.com/uploadxml.php" 
+0

정말 고마워요. 나는 그것이 매우 쉬운 무엇인가 알고 있었다. – NielMalhotra