Error in the code while trying to read from URL using XML, xmlParse

Moh

I have to read the below link and answer the below question after the code http://www.ggobi.org/book/data/australian-crabs.xml

      library(XML)
crabs <- xmlParse('http://www.ggobi.org/book/data/australian-crabs.xml')
root <- xmlRoot(crabs)
xmlName(root)
varInfo <- root[[1]][[2]]
varInfo

as.vector(unlist(xmlApply(varInfo, xmlAttrs)))
     

The question is How many total number of records are does records have? Extract the text value for record 11.

**my answer is **

library(XML)

# download the xml data and save it in a file
url <- "http://www.ggobi.org/book/data/australian-crabs.xml"
download.file(url, destfile = "australian-crabs.xml")

# parse the xml data
xml_data <- xmlParse("australian-crabs.xml")

# extract the data from the xml
datPath <- "//record"
datValue <- xpathApply(xml_data, datPath, xmlValue)

# find the total number of records
num_records <- length(datValue)
cat("Total number of records:", num_records, "\n")

# extract the text value for record 11
record11 <- xmlParse(datValue[11])
text_value <- xmlValue(getNodeSet(record11, ".//text")[[1]])
cat("Text value for record 11:", text_value, "\n")

but I have the below error

trying URL 'http://www.ggobi.org/book/data/australian-crabs.xml'
Content type 'application/xml' length 20212 bytes (19 KB)
==================================================
downloaded 19 KB

Total number of records: 208 
Error in file.exists(file) : invalid 'file' argument

I need to solve this error

G5W

You already extracted the values of the records when you ran

datValue <- xpathApply(xml_data, datPath, xmlValue)

so datValue does not contain xml, just the values. You need to use

text_value <- datValue[[11]]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

401 error while trying to connect to a Https url from Java

From Dev

ERROR_CODE_MERCHANT_ACCOUNT_ERROR (405) while trying Android Pay in TEST environment using Google Sample Code

From Dev

FluentFTP - Getting error while connecting "Timed out trying to read data from the socket stream!"

From Dev

Getting error while trying to read csv using pandas Python due to extra column values

From Dev

How to fix ' Error in UseMethod("xml_find_all") ' while trying to webscrape using rvest

From Dev

Observed error while trying to fetch details from xml that stored in variable

From Dev

Error while trying to debug demandware pipeline code using eclipse

From Dev

Error while trying to read XML values in Code

From Dev

C# Reading XML from url while using XMLSerializer

From Dev

Read xml lines from url

From Dev

getPackageManager() error while trying to obtain Android hash key from Android code

From Dev

Trying to get xml from url but getting FATAL ERROR: main

From Dev

I get the error as "missing an @XmlRootElement annotation" while trying to marshall an object into xml file using JAXB

From Dev

Stanford POS tagger error when trying to read the tagger file from URL

From Dev

C# code to Read XML From URL

From Dev

FileNotFoundException while trying to read from SDCard

From Dev

Error code on my while loop, trying to read line by line through a file. in C

From Dev

Error when trying to read to read from Entry

From Dev

NullPointerException when trying to read info from an url using HttpURLConnection

From Dev

Error while calling External REST URL from netsuite using token

From Dev

Error while trying to read from a Json file in c#

From Dev

Error while trying to display images from FirebaseFirestore using picasso

From Dev

Error while trying to get download URL from firebase-storage

From Dev

Why am I getting a "Permission denied error" while trying to read a cell value using openpyxl python?

From Dev

.Net Core 3.0 while trying take html content from url This error page might contain sensitive error

From Dev

getting error while trying to play Audio from URL in chrome extension

From Dev

Getting 'Error occurred while GetObject. S3 Error Code: NoSuchKey' while trying to create stack using cloudFormation template

From Dev

Error "Cannot read properties of undefined" while trying to pass data from child to parent component

From Dev

I get error while trying to read text from file in reactjs/tauri

Related Related

  1. 1

    401 error while trying to connect to a Https url from Java

  2. 2

    ERROR_CODE_MERCHANT_ACCOUNT_ERROR (405) while trying Android Pay in TEST environment using Google Sample Code

  3. 3

    FluentFTP - Getting error while connecting "Timed out trying to read data from the socket stream!"

  4. 4

    Getting error while trying to read csv using pandas Python due to extra column values

  5. 5

    How to fix ' Error in UseMethod("xml_find_all") ' while trying to webscrape using rvest

  6. 6

    Observed error while trying to fetch details from xml that stored in variable

  7. 7

    Error while trying to debug demandware pipeline code using eclipse

  8. 8

    Error while trying to read XML values in Code

  9. 9

    C# Reading XML from url while using XMLSerializer

  10. 10

    Read xml lines from url

  11. 11

    getPackageManager() error while trying to obtain Android hash key from Android code

  12. 12

    Trying to get xml from url but getting FATAL ERROR: main

  13. 13

    I get the error as "missing an @XmlRootElement annotation" while trying to marshall an object into xml file using JAXB

  14. 14

    Stanford POS tagger error when trying to read the tagger file from URL

  15. 15

    C# code to Read XML From URL

  16. 16

    FileNotFoundException while trying to read from SDCard

  17. 17

    Error code on my while loop, trying to read line by line through a file. in C

  18. 18

    Error when trying to read to read from Entry

  19. 19

    NullPointerException when trying to read info from an url using HttpURLConnection

  20. 20

    Error while calling External REST URL from netsuite using token

  21. 21

    Error while trying to read from a Json file in c#

  22. 22

    Error while trying to display images from FirebaseFirestore using picasso

  23. 23

    Error while trying to get download URL from firebase-storage

  24. 24

    Why am I getting a "Permission denied error" while trying to read a cell value using openpyxl python?

  25. 25

    .Net Core 3.0 while trying take html content from url This error page might contain sensitive error

  26. 26

    getting error while trying to play Audio from URL in chrome extension

  27. 27

    Getting 'Error occurred while GetObject. S3 Error Code: NoSuchKey' while trying to create stack using cloudFormation template

  28. 28

    Error "Cannot read properties of undefined" while trying to pass data from child to parent component

  29. 29

    I get error while trying to read text from file in reactjs/tauri

HotTag

Archive