2011-05-08 6 views
0

다음 XML 예제가 있는데 R 데이터 프레임에 "listing"데이터를 가져 오려고합니다. 예 : xmlToDataFrame 함수를 URL로 시작하는 작업을 수행하도록 구성하는 방법은 무엇입니까? R의 XML to Dataframe

<response> 
<area_name/> 
<bounding_box> 
<latitude_max>51.667389</latitude_max> 
<latitude_min>51.385262</latitude_min> 
<longitude_max>0.137236</longitude_max> 
<longitude_min>-0.34844</longitude_min> 
</bounding_box> 
<country>England</country> 
<county>London</county> 
<latitude>51.5263255</latitude> 
<listing> 
<agent_address>218a Brick Lane</agent_address> 
<agent_logo/> 
<agent_name>Salik & Co</agent_name> 
<agent_phone>020 3318 7059</agent_phone> 
<country/> 
<county>London</county> 
<description> 


Description: 
Salik & Co is offering this Commercial Freehold Property for sale on Wise Road, Stratford, London E15... Premises consists of: 
12 X 2 Bedroom Flat AS Following- 
* 2x Pent House With One Bath 
* 2x Flat With 2 Double Bed With 2 Bath 
* 8x Flat With 1 Bath 
* 4x Car Park 
* 4x floor with ground floor parking 
* Lift 
* Flat 11 & 13 Pent House with 500 sqft Terrace. 
* Flat 12 & Ground Floor shop sold for Long lease. Area Profile: 
Stratford is a place in the London Borough of Newham in East London. It will be the primary location of the 2012 Summer Olympics. The area is identified in the London Plan as one of 35 major centres in Greater London. Stratford has been a focus of regeneration for some years, and is the location of a number of major projects.... Property Location: 
Set only moments from the vibrant amenities of Stratford, Olympic park, Westfield Shopping centre. This modern 2 bed stunning flat offers contemporary accommodation with a private balcony, in a fabulous new eco building close to the green open spaces of East London 
Situated on Stratford High Street the property enjoys swift access into the fashionable bars, restaurants and boutiques of Stratford High Street. Transport links include Stratford (Central line, Jubilee Line and British Rail) which provide further link to district line. Price: 
Asking price £2.8 million. For further information contact: 
Ryan - 
Salik - 
Office - 
Email - 
Web - 

</description> 
<details_url>http://www.zoopla.co.uk/for-sale/details/4507257</details_url> 
<displayable_address>Wise Road, London</displayable_address> 
<image_caption/> 
<image_url> 
http://images.zoopla.co.uk/52367ed1b61a63c1b93f1ec0a70d39f83d590c74_354_255.jpg 
</image_url> 
<latitude>51.53477</latitude> 
<listing_id>4507257</listing_id> 
<listing_status>sale</listing_status> 
<longitude>-0.0045035</longitude> 
<num_bathrooms>0</num_bathrooms> 
<num_bedrooms>0</num_bedrooms> 
<num_floors>0</num_floors> 
<num_recepts>0</num_recepts> 
<outcode>E15</outcode> 
<post_town>London</post_town> 
<price>2800000</price> 
<price_change> 
<date>2010-04-27 00:42:05</date> 
<price>3000000</price> 
</price_change> 
<price_change> 
<date>2010-07-04 03:21:14</date> 
<price>2800000</price> 
</price_change> 
<property_type/> 
<street_name>Commercial Property</street_name> 
<thumbnail_url> 
http://images.zoopla.co.uk/52367ed1b61a63c1b93f1ec0a70d39f83d590c74_80_60.jpg 
</thumbnail_url> 
</listing> 
<listing> 
<agent_address>Rawlings House 2a Milner Street</agent_address> 
<agent_logo> 
http://static.zoopla.co.uk/zoopla_static_agent_logo_(29807).gif 
</agent_logo> 
<agent_name>Marsh & Parsons</agent_name> 
<agent_phone>020 3318 6922</agent_phone> 
<country/> 
<county>London</county> 
<description> 
A stunning, three bed mews house with spacious, roof terrace in a popular gated development off Milner Street and ideally located for the nearby amenities of South Kensington and Knightsbridge. A large reception room and a contemporary, open plan kitchen occupy the ground floor, while the first floor houses two double bedrooms and a modern family bathroom. An additional shower room can be found on the second floor which also has a substantial area suitable for a third bedroom and access to the sunny roof terrace. Located in the heart SW3's Brompton area, there is a multitude of local amenities available at Chelsea's popular King's Road and Sloane Street, while the shops, bars and restaurants of Brompton Road and Knightsbridge are easily reached. St. Catherine's Mews is ideally located for the Underground stations at both Sloane Square (Circle and District Lines) and South Kensington (Piccadilly, Circle and District Lines) while such a central location provides a number of convenient bus services. For transport links into and out of London the motorways can be accessed via the nearby A4.The property also has planning permission to extend the 2nd floor to encompass some of the roof terrace that would create greater internal square footage. 
</description> 
<details_url>http://www.zoopla.co.uk/for-sale/details/491528</details_url> 
<displayable_address>St Catherines Mews, London SW3</displayable_address> 
<floor_plan> 
http://content.zoopla.co.uk/5cb125b77de67eb6717bd8a2c74ba7edb6839959.jpg 
</floor_plan> 
<image_caption>Picture No.46</image_caption> 
<image_url> 
http://images.zoopla.co.uk/0867139d8bc2e2aac63056d75bbce1677de438c6_354_255.jpg 
</image_url> 
<latitude>51.493774</latitude> 
<listing_id>491528</listing_id> 
<listing_status>sale</listing_status> 
<longitude>-0.164762</longitude> 
<num_bathrooms>0</num_bathrooms> 
<num_bedrooms>2</num_bedrooms> 
<num_floors>0</num_floors> 
<num_recepts>0</num_recepts> 
<outcode>SW3</outcode> 
<post_town>London</post_town> 
<price>1500000</price> 
<price_change> 
<date>2009-05-16 01:40:29</date> 
<price>1350000</price> 
</price_change> 
<price_change> 
<date>2010-02-20 00:30:24</date> 
<price>1450000</price> 
</price_change> 
<price_change> 
<date>2011-02-12 00:31:53</date> 
<price>1500000</price> 
</price_change> 
<property_type>Town house</property_type> 
<street_name>London</street_name> 
<thumbnail_url> 
http://images.zoopla.co.uk/0867139d8bc2e2aac63056d75bbce1677de438c6_80_60.jpg 
</thumbnail_url> 
</listing> 
<listing> 
<agent_address>175 Putney High Street, Putney</agent_address> 
<agent_logo> 
http://static.zoopla.co.uk/zoopla_static_agent_logo_(47723).jpeg 
</agent_logo> 
<agent_name>Foxtons - Putney</agent_name> 
<agent_phone>020 3318 9160</agent_phone> 
<country/> 
<county>London</county> 
<description> 
A stunning four bedroomed house offering exceptionally spacious accommodation with stylish interior throughout. The property is arranged over four floors and comprises two good-sized reception rooms, generous 29' kitchen/dining room, four bedrooms (two with en suite), two bathrooms, two shower rooms, utility room, guest cloakroom, attractive garden and off-street parking. Akehurst Street is a quiet residential road located close to the green expanses of Richmond Park, and close to amenities in Roehampton with a greater selection of shops, bars and restaurants within easy reach in Putney. The area is well served by a number of local bus routes, while the nearby A3 provides motorists with a fast route into central London and to the South-West. 
</description> 
<details_url>http://www.zoopla.co.uk/for-sale/details/14226965</details_url> 
<displayable_address>Akehurst Street, London</displayable_address> 
<image_caption/> 
<image_url> 
http://images.zoopla.co.uk/5a24b05bff28865405aee72bcf4c46ae2ce299a4_354_255.jpg 
</image_url> 
<latitude>51.450905</latitude> 
<listing_id>14226965</listing_id> 
<listing_status>sale</listing_status> 
<longitude>-0.242762</longitude> 
<num_bathrooms>0</num_bathrooms> 
<num_bedrooms>4</num_bedrooms> 
<num_floors>0</num_floors> 
<num_recepts>0</num_recepts> 
<outcode>SW15</outcode> 
<post_town>London</post_town> 
<price>1499950</price> 
<property_type>Town house</property_type> 
<street_name>Akehurst Street</street_name> 
<thumbnail_url> 
http://images.zoopla.co.uk/5a24b05bff28865405aee72bcf4c46ae2ce299a4_80_60.jpg 
</thumbnail_url> 
</listing> 
<listing> 
<agent_address>55 Fulham Broadway, Fulham</agent_address> 
<agent_logo> 
http://static.zoopla.co.uk/zoopla_static_agent_logo_(47732).jpeg 
</agent_logo> 
<agent_name>Foxtons - Fulham</agent_name> 
<agent_phone>020 3318 6868</agent_phone> 
<country/> 
<county>London</county> 
<description> 
Located on a quiet residential street in Fulham, this great four bedroomed house offers spacious accommodation with loft conversion and south-facing flat roof. Arranged over three floors, the property comprises reception room with bay window, dining room, kitchen with space to dine and access to the garden, top floor master bedroom with en suite shower room, large second bedroom, two additional bedrooms, bathroom and outside store room. The property is situated on a tree-lined street, ideally located just moments from the local amenities on both Dawes Road and Lillie Road and is within easy reach of a more a comprehensive range of bars, shops and restaurants on nearby Fulham Broadway. The closest underground station is Fulham Broadway (District Line), providing convenient access to various central and greater London destinations. 
</description> 
<details_url>http://www.zoopla.co.uk/for-sale/details/14351415</details_url> 
<displayable_address>Prothero Road, London</displayable_address> 
<image_caption/> 
<image_url> 
http://images.zoopla.co.uk/a9d983b76018a07537de832224bb5174099c2758_354_255.jpg 
</image_url> 
<latitude>51.48186</latitude> 
<listing_id>14351415</listing_id> 
<listing_status>sale</listing_status> 
<longitude>-0.208447</longitude> 
<num_bathrooms>0</num_bathrooms> 
<num_bedrooms>4</num_bedrooms> 
<num_floors>0</num_floors> 
<num_recepts>0</num_recepts> 
<outcode>SW6</outcode> 
<post_town>London</post_town> 
<price>750000</price> 
<property_type>Town house</property_type> 
<street_name>Prothero Road</street_name> 
<thumbnail_url> 
http://images.zoopla.co.uk/a9d983b76018a07537de832224bb5174099c2758_80_60.jpg 
</thumbnail_url> 
</listing> 
<longitude>-0.105602</longitude> 
<postcode/> 
<result_count>76494</result_count> 
<street/> 
<town/> 
</response> 

는 입력 데이터는 "직사각형"할 것을 요구

답변

1

Dataframes 감사합니다. 분명히 그러한 데이터 배열이 없습니다. R의 목록 데이터 형식이 이와 같은 경우에 더 적합합니다. 다른 문제는이 파일에 앰퍼샌드 "&"이있는 것 같습니다. "&"이 html의 이스케이프 문자 인 것을 감안할 때 여기서보다 안전한 방법은 "&"을 "& amp"으로 대체하는 것이 었습니다. "&"을 모두 "and"로 변경하면 xmlToList()를 통해 해당 목록을 읽고 해당 목록을 만들 수 있습니다 (그러나 유효한 HTML이 포함되어 있으면 다른 파일에 손상을 줄 수 있음). 은`RCurl`에

xmlToList(f)[grep("listing", names(xmlToList(f)))] 

(당신은 URL을 제공해야합니다.)

+0

'curlEscape' :

목록 데이터 목록의 이름을 '목록'일치에 의해 추출 될 수있다 패키지를 사용하여'&'문자를 살균 할 수 있습니다. –