如何将尖括号&lt;&gt; <!---->数据导入R中

时间:2015-10-11 13:04:26

标签: r xml import

请任何人都可以帮我从unix可执行文件中将尖括号数据导入到R中。它似乎是一种XML类型,所以,我尝试使用XML解析器,但它失败了。

我附上了示例文件。 提前谢谢。

https://drive.google.com/file/d/0B97ow4h4jwHcRTVtWHdudDJ0c1k/view?usp=sharing

2 个答案:

答案 0 :(得分:0)

&#39;&安培;&#39;字符存在于XML文档的元素中。

以下是一个例子:

<DOC>
<DATE>01/07/2009</DATE>
<AUTHOR>Debce</AUTHOR>
<TEXT>I have owned my MDX for about 1 1/2 yrs & have loved every minute of driving the 24k problem free miles on it! It is so much fun to drive; looks & feels luxurious so no problem pulling up to upscale places! I didn't want to give up space to pop things in the back and go so I keep the third seat down & purchased the rubber mat for the back. I have plenty of room while at the same time I am "zippy"; easily pulling into parking spaces and getting around town. I love the navigation system, although it does need updating and the bluetooth is wonderful, although for some reason it keeps unhooking my Treo phone which the Acura people say is the phone's fault. LOVE IT & would buy it again.</TEXT>
<FAVORITE>Large storage area, hands free phone with the bluetooth & voice recognition is safe. The heaviness of it feels safe and large interior is very comfortable. </FAVORITE>
</DOC>

&#39;&安培;&#39;字符应该被转义。

  1. &#39;&GT;&#39;
  2. &#39;&LT;&#39;
  3. &#39;&安培;&#39;
  4. &#39;%&#39;
  5. 字符是应在XML文档中转义的特殊字符。

答案 1 :(得分:0)

这是一种将数据提取到字符矩阵中的方法。

> require(XML)
> x <- htmlParse("/temp/2007_acura_mdx")
> 
> # get the 'DOC'
> docs <- getNodeSet(x, "//doc")
> 
> # display one
> docs[[1]]
<doc>
  <date>07/31/2009</date>
  <author>FlewByU</author>
  <text>I just moved to Germany two months ago and bought an 07 MDX from another military member. It has everything I could want. We just returned from a week driving through the Alps and this SUV is simply amazing. Granted, I get to drive it much faster than I could in the states, but even at 120 MPH, it was rock solid. We need the AWD for the snow and the kids stay entertained with the AV system. Plenty of passing power and very comfortable on long trips. Acuras are rare in Germany and I get stares all the time by curious Bavarians wondering what kind of vehicle I have. If you are in the market for a luxury SUV for family touring, with cool tech toys to play with, MDX can't be beat. </text>
  <favorite>The separate controls for the rear passengers are awesome. I can control temp and AV from the front or switch to rear. Sound system is amazing. I will sometimes sit in the driveway and just listen. Also has a 120v outlet in console. Great for us since we live with 220v and need 120 on occasion. </favorite>
</doc> 
> 
> # process docs getting all fields -- need to transpose
> results <- t(sapply(docs, function(x) xmlSApply(x, xmlValue)))
> 
> # show head
> head(results)
     date         author     
[1,] "07/31/2009" "FlewByU"  
[2,] "07/30/2009" "cvillemdx"
[3,] "06/22/2009" "Pleased"  
[4,] "04/13/2009" "wasatch7" 
[5,] "04/06/2009" "mnozek"   
[6,] "01/07/2009" "Debce"    
     text                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
[1,] "I just moved to Germany two months ago and bought an 07 MDX from another military member. It has everything I could want. We just returned from a week driving through the Alps and this SUV is simply amazing. Granted, I get to drive it much faster than I could in the states, but even at 120 MPH, it was rock solid. We need the AWD for the snow and the kids stay entertained with the AV system. Plenty of passing power and very comfortable on long trips. Acuras are rare in Germany and I get stares all the time by curious Bavarians wondering what kind of vehicle I have. If you are in the market for a luxury SUV for family touring, with cool tech toys to play with, MDX can't be beat. "      
[2,] "After months of careful research and test drives at BMW, Lexus, Volvo, etc. I settled on the MDX without a doubt in mind. I love the way the car handles, no stiffness or resistance in the steering or acceleration. The interior design is a little Star Trek for me, but once I figured everything out, it is a pleasure to have all the extras (XM radio, navigation, Bluetooth, backup camera, etc.)"                                                                                                                                                                                                                                                                                                           
[3,] "I'm two years into a three year lease and I love this car. The only thing I would change would be the shape of the grill...THAT'S IT. Everything else is perfect. Great performance, plenty of power and AWD when skiing, plenty of room for baggage, great MPG for an SUV, navi system is far superior to GM's Suburban (don't have to put in park to change your destination, etc). Zero problems...just gas and oil changes. One beautiful car...except for the sho-gun shield looking grill."                                                                                                                                                                                                                    
[4,] "First luxury crossover SUV I have owned. MDX won out over the Lexus, and cost less for a very well equipped base package. Handling, power and ride are outstanding. Back seats are a little less comfortable for my tall teenagers. Back cargo area is very roomy, and easily expandable with 3rd seat folded and back seats down. I drive up snowy, often treacherous mountain canyons to ski in the winter. The SH-AWD system, coupled with the manual shift mode (for descents), is outstanding. The MDX is much better in the snow than 3 truck base SUVs, I have owned previously. "                                                                                                                            
[5,] "This is the first Japanese SUV we have had in a while. Last SUV's were Yukon XL and Envoy XL. This beats them out by far. Performs almost as well as our Mercedes e class but has the utility of our Envoy. We always take this on trips and it is very comfortable. The third row is great for smaller children but not so much for adults. Best SUV so far. No problems within our almost 2 years ownership."                                                                                                                                                                                                                                                                                                      
[6,] "I have owned my MDX for about 1 1/2 yrs & have loved every minute of driving the 24k problem free miles on it! It is so much fun to drive; looks & feels luxurious so no problem pulling up to upscale places! I didn't want to give up space to pop things in the back and go so I keep the third seat down & purchased the rubber mat for the back. I have plenty of room while at the same time I am \"zippy\"; easily pulling into parking spaces and getting around town. I love the navigation system, although it does need updating and the bluetooth is wonderful, although for some reason it keeps unhooking my Treo phone which the Acura people say is the phone's fault. LOVE IT & would buy it again."
     favorite                                                                                                                                                                                                                                                                                                  
[1,] "The separate controls for the rear passengers are awesome. I can control temp and AV from the front or switch to rear. Sound system is amazing. I will sometimes sit in the driveway and just listen. Also has a 120v outlet in console. Great for us since we live with 220v and need 120 on occasion. "
[2,] "The self-adjusting side mirrors which rotate to give you a view of the curb/lines as you back up. Makes backing into parking spaces and parallel parking a breeze, along with the back-up camera. Also a fan of the push-to-talk for my cell phone."                                                     
[3,] "Navi is easy, hands-free is great, AWD is perfect."                                                                                                                                                                                                                                                      
[4,] "AWD system, exterior styling, cargo room"                                                                                                                                                                                                                                                                
[5,] "Navigation, sound system, bluetooth, comfort, acceleration, performance, all wheel drive ability."                                                                                                                                                                                                       
[6,] "Large storage area, hands free phone with the bluetooth & voice recognition is safe. The heaviness of it feels safe and large interior is very comfortable. "                                                                                                                                            
> 
> 
>