WedX - журнал о программировании и компьютерных науках

Как я могу получить текст элемента XML из вывода ответа API Zillow с помощью R?

Я работаю с выводом ответа службы API Zillow в R; похоже, что он в формате XML, и я хотел бы получить текст из определенного элемента в ответе. Однако, когда я попытался проанализировать XML-файл с помощью xmlTreeParse, возникает ошибка, указывающая, что «XML-содержимое не похоже на XML». Как я могу получить текст определенного элемента в ответе API?

Я немного новичок в R, поэтому любой метод или совет относительно того, как преобразовать этот ответ или получить текст элемента, был бы потрясающим. Я думаю, что проблема заключается в формате ответа API.

library(ZillowR)
library(XML)
library(RCurl)

## one must have a "zws_id", Zillow's API key ##

reply <- GetDeepSearchResults(address = '33 Pratt Rd', citystatezip = 'Scituate, MA',
  rentzestimate = FALSE, zws_id = "XXXXXX",
  url = "https://www.zillow.com/webservice/GetDeepSearchResults.htm")

reply

doc = xmlTreeParse(reply, asText = TRUE, useInternal = TRUE)
xmlValue(doc[["//amount"]])

вывод "ответить"

$request
$request$address
[1] "33 Pratt Rd"

$request$citystatezip
[1] "Scituate, MA"


$message
$message$text
[1] "Request successfully processed"

$message$code
[1] "0"


$response
<response>
 <results>
  <result>
   <zpid>57223487</zpid>
   <links>
    <homedetails>https://www.zillow.com/homedetails/33-Pratt-Rd-Scituate-MA-02066/57223487_zpid/</homedetails>
    <graphsanddata>https://www.zillow.com/homedetails/33-Pratt-Rd-Scituate-MA-02066/57223487_zpid/#charts-and-data</graphsanddata>
    <mapthishome>https://www.zillow.com/homes/57223487_zpid/</mapthishome>
    <comparables>https://www.zillow.com/homes/comps/57223487_zpid/</comparables>
   </links>
   <address>
    <street>33 Pratt Rd</street>
    <zipcode>02066</zipcode>
    <city>Scituate</city>
    <state>MA</state>
    <latitude>42.211625</latitude>
    <longitude>-70.775096</longitude>
   </address>
   <FIPScounty>25023</FIPScounty>
   <useCode>SingleFamily</useCode>
   <taxAssessmentYear>2019</taxAssessmentYear>
   <taxAssessment>441300.0</taxAssessment>
   <yearBuilt>1972</yearBuilt>
   <lotSizeSqFt>21400</lotSizeSqFt>
   <finishedSqFt>1363</finishedSqFt>
   <bathrooms>1.0</bathrooms>
   <bedrooms>3</bedrooms>
   <totalRooms>6</totalRooms>
   <zestimate>
    <amount currency="USD">472759</amount>
    <last-updated>06/16/2019</last-updated>
Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.    <oneWeekChange deprecated="true"/>
    <valueChange duration="30" currency="USD">2131</valueChange>
    <valuationRange>
     <low currency="USD">449121</low>
     <high currency="USD">501125</high>
    </valuationRange>
    <percentile>0</percentile>
   </zestimate>
   <localRealEstate>
    <region name="Scituate" id="397319" type="city">
     <zindexValue>551,000</zindexValue>
     <links>
      <overview>https://www.zillow.com/local-info/MA-Scituate/r_397319/</overview>
      <forSaleByOwner>https://www.zillow.com/scituate-ma/fsbo/</forSaleByOwner>
      <forSale>https://www.zillow.com/scituate-ma/</forSale>
     </links>
    </region>
   </localRealEstate>
  </result>
 </results>
</response>

Это немного обширно, но это текстовое представление вывода вызова/ответа...

dput(reply)

list(request = list(address = "33 Pratt Rd", citystatezip = "Scituate, MA"), 
    message = list(text = "Request successfully processed", code = "0"), 
    response = structure(list(name = "response", attributes = NULL, 
        children = list(results = structure(list(name = "results", 
            attributes = NULL, children = list(result = structure(list(
                name = "result", attributes = NULL, children = list(
                  zpid = structure(list(name = "zpid", attributes = NULL, 
                    children = list(text = structure(list(name = "text", 
                      attributes = NULL, children = NULL, namespace = NULL, 
                      namespaceDefinitions = NULL, value = "57223487"), class = c("XMLTextNode", 
                    "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                    "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), links = structure(list(name = "links", 
                    attributes = NULL, children = list(homedetails = structure(list(
                      name = "homedetails", attributes = NULL, 
                      children = list(text = structure(list(name = "text", 
                        attributes = NULL, children = NULL, namespace = NULL, 
                        namespaceDefinitions = NULL, value = "https://www.zillow.com/homedetails/33-Pratt-Rd-Scituate-MA-02066/57223487_zpid/"), class = c("XMLTextNode", 
                      "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    )), graphsanddata = structure(list(name = "graphsanddata", 
                      attributes = NULL, children = list(text = structure(list(
                        name = "text", attributes = NULL, children = NULL, 
                        namespace = NULL, namespaceDefinitions = NULL, 
                        value = "https://www.zillow.com/homedetails/33-Pratt-Rd-Scituate-MA-02066/57223487_zpid/#charts-and-data"), class = c("XMLTextNode", 
                      "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    )), mapthishome = structure(list(name = "mapthishome", 
                      attributes = NULL, children = list(text = structure(list(
                        name = "text", attributes = NULL, children = NULL, 
                        namespace = NULL, namespaceDefinitions = NULL, 
                        value = "https://www.zillow.com/homes/57223487_zpid/"), class = c("XMLTextNode", 
                      "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    )), comparables = structure(list(name = "comparables", 
                      attributes = NULL, children = list(text = structure(list(
                        name = "text", attributes = NULL, children = NULL, 
                        namespace = NULL, namespaceDefinitions = NULL, 
                        value = "https://www.zillow.com/homes/comps/57223487_zpid/"), class = c("XMLTextNode", 
                      "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    ))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), address = structure(list(name = "address", 
                    attributes = NULL, children = list(street = structure(list(
                      name = "street", attributes = NULL, children = list(
                        text = structure(list(name = "text", 
                          attributes = NULL, children = NULL, 
                          namespace = NULL, namespaceDefinitions = NULL, 
                          value = "33 Pratt Rd"), class = c("XMLTextNode", 
                        "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                        "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    )), zipcode = structure(list(name = "zipcode", 
                      attributes = NULL, children = list(text = structure(list(
                        name = "text", attributes = NULL, children = NULL, 
                        namespace = NULL, namespaceDefinitions = NULL, 
                        value = "02066"), class = c("XMLTextNode", 
                      "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    )), city = structure(list(name = "city", 
                      attributes = NULL, children = list(text = structure(list(
                        name = "text", attributes = NULL, children = NULL, 
                        namespace = NULL, namespaceDefinitions = NULL, 
                        value = "Scituate"), class = c("XMLTextNode", 
                      "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    )), state = structure(list(name = "state", 
                      attributes = NULL, children = list(text = structure(list(
                        name = "text", attributes = NULL, children = NULL, 
                        namespace = NULL, namespaceDefinitions = NULL, 
                        value = "MA"), class = c("XMLTextNode", 
                      "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    )), latitude = structure(list(name = "latitude", 
                      attributes = NULL, children = list(text = structure(list(
                        name = "text", attributes = NULL, children = NULL, 
                        namespace = NULL, namespaceDefinitions = NULL, 
                        value = "42.211625"), class = c("XMLTextNode", 
                      "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    )), longitude = structure(list(name = "longitude", 
                      attributes = NULL, children = list(text = structure(list(
                        name = "text", attributes = NULL, children = NULL, 
                        namespace = NULL, namespaceDefinitions = NULL, 
                        value = "-70.775096"), class = c("XMLTextNode", 
                      "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    ))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), FIPScounty = structure(list(name = "FIPScounty", 
                    attributes = NULL, children = list(text = structure(list(
                      name = "text", attributes = NULL, children = NULL, 
                      namespace = NULL, namespaceDefinitions = NULL, 
                      value = "25023"), class = c("XMLTextNode", 
                    "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                    "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), useCode = structure(list(name = "useCode", 
                    attributes = NULL, children = list(text = structure(list(
                      name = "text", attributes = NULL, children = NULL, 
                      namespace = NULL, namespaceDefinitions = NULL, 
                      value = "SingleFamily"), class = c("XMLTextNode", 
                    "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                    "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), taxAssessmentYear = structure(list(name = "taxAssessmentYear", 
                    attributes = NULL, children = list(text = structure(list(
                      name = "text", attributes = NULL, children = NULL, 
                      namespace = NULL, namespaceDefinitions = NULL, 
                      value = "2019"), class = c("XMLTextNode", 
                    "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                    "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), taxAssessment = structure(list(name = "taxAssessment", 
                    attributes = NULL, children = list(text = structure(list(
                      name = "text", attributes = NULL, children = NULL, 
                      namespace = NULL, namespaceDefinitions = NULL, 
                      value = "441300.0"), class = c("XMLTextNode", 
                    "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                    "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), yearBuilt = structure(list(name = "yearBuilt", 
                    attributes = NULL, children = list(text = structure(list(
                      name = "text", attributes = NULL, children = NULL, 
                      namespace = NULL, namespaceDefinitions = NULL, 
                      value = "1972"), class = c("XMLTextNode", 
                    "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                    "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), lotSizeSqFt = structure(list(name = "lotSizeSqFt", 
                    attributes = NULL, children = list(text = structure(list(
                      name = "text", attributes = NULL, children = NULL, 
                      namespace = NULL, namespaceDefinitions = NULL, 
                      value = "21400"), class = c("XMLTextNode", 
                    "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                    "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), finishedSqFt = structure(list(name = "finishedSqFt", 
                    attributes = NULL, children = list(text = structure(list(
                      name = "text", attributes = NULL, children = NULL, 
                      namespace = NULL, namespaceDefinitions = NULL, 
                      value = "1363"), class = c("XMLTextNode", 
                    "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                    "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), bathrooms = structure(list(name = "bathrooms", 
                    attributes = NULL, children = list(text = structure(list(
                      name = "text", attributes = NULL, children = NULL, 
                      namespace = NULL, namespaceDefinitions = NULL, 
                      value = "1.0"), class = c("XMLTextNode", 
                    "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                    "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), bedrooms = structure(list(name = "bedrooms", 
                    attributes = NULL, children = list(text = structure(list(
                      name = "text", attributes = NULL, children = NULL, 
                      namespace = NULL, namespaceDefinitions = NULL, 
                      value = "3"), class = c("XMLTextNode", 
                    "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                    "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), totalRooms = structure(list(name = "totalRooms", 
                    attributes = NULL, children = list(text = structure(list(
                      name = "text", attributes = NULL, children = NULL, 
                      namespace = NULL, namespaceDefinitions = NULL, 
                      value = "6"), class = c("XMLTextNode", 
                    "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                    "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), zestimate = structure(list(name = "zestimate", 
                    attributes = NULL, children = list(amount = structure(list(
                      name = "amount", attributes = c(currency = "USD"), 
                      children = list(text = structure(list(name = "text", 
                        attributes = NULL, children = NULL, namespace = NULL, 
                        namespaceDefinitions = NULL, value = "472404"), class = c("XMLTextNode", 
                      "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    )), `last-updated` = structure(list(name = "last-updated", 
                      attributes = NULL, children = list(text = structure(list(
                        name = "text", attributes = NULL, children = NULL, 
                        namespace = NULL, namespaceDefinitions = NULL, 
                        value = "06/17/2019"), class = c("XMLTextNode", 
                      "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    )), oneWeekChange = structure(list(name = "oneWeekChange", 
                      attributes = c(deprecated = "true"), children = NULL, 
                      namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    )), valueChange = structure(list(name = "valueChange", 
                      attributes = c(duration = "30", currency = "USD"
                      ), children = list(text = structure(list(
                        name = "text", attributes = NULL, children = NULL, 
                        namespace = NULL, namespaceDefinitions = NULL, 
                        value = "1494"), class = c("XMLTextNode", 
                      "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    )), valuationRange = structure(list(name = "valuationRange", 
                      attributes = NULL, children = list(low = structure(list(
                        name = "low", attributes = c(currency = "USD"), 
                        children = list(text = structure(list(
                          name = "text", attributes = NULL, children = NULL, 
                          namespace = NULL, namespaceDefinitions = NULL, 
                          value = "448784"), class = c("XMLTextNode", 
                        "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                        "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                      "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass")), high = structure(list(name = "high", 
                        attributes = c(currency = "USD"), children = list(
                          text = structure(list(name = "text", 
                            attributes = NULL, children = NULL, 
                            namespace = NULL, namespaceDefinitions = NULL, 
                            value = "500748"), class = c("XMLTextNode", 
                          "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                          "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                      "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    )), percentile = structure(list(name = "percentile", 
                      attributes = NULL, children = list(text = structure(list(
                        name = "text", attributes = NULL, children = NULL, 
                        namespace = NULL, namespaceDefinitions = NULL, 
                        value = "0"), class = c("XMLTextNode", 
                      "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                      "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    ))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  )), localRealEstate = structure(list(name = "localRealEstate", 
                    attributes = NULL, children = list(region = structure(list(
                      name = "region", attributes = c(name = "Scituate", 
                      id = "397319", type = "city"), children = list(
                        zindexValue = structure(list(name = "zindexValue", 
                          attributes = NULL, children = list(
                            text = structure(list(name = "text", 
                              attributes = NULL, children = NULL, 
                              namespace = NULL, namespaceDefinitions = NULL, 
                              value = "551,000"), class = c("XMLTextNode", 
                            "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                            "oldClass"))), namespace = NULL, 
                          namespaceDefinitions = NULL), class = c("XMLNode", 
                        "RXMLAbstractNode", "XMLAbstractNode", 
                        "oldClass")), links = structure(list(
                          name = "links", attributes = NULL, 
                          children = list(overview = structure(list(
                            name = "overview", attributes = NULL, 
                            children = list(text = structure(list(
                              name = "text", attributes = NULL, 
                              children = NULL, namespace = NULL, 
                              namespaceDefinitions = NULL, value = "https://www.zillow.com/local-info/MA-Scituate/r_397319/"), class = c("XMLTextNode", 
                            "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                            "oldClass"))), namespace = NULL, 
                            namespaceDefinitions = NULL), class = c("XMLNode", 
                          "RXMLAbstractNode", "XMLAbstractNode", 
                          "oldClass")), forSaleByOwner = structure(list(
                            name = "forSaleByOwner", attributes = NULL, 
                            children = list(text = structure(list(
                              name = "text", attributes = NULL, 
                              children = NULL, namespace = NULL, 
                              namespaceDefinitions = NULL, value = "https://www.zillow.com/scituate-ma/fsbo/"), class = c("XMLTextNode", 
                            "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                            "oldClass"))), namespace = NULL, 
                            namespaceDefinitions = NULL), class = c("XMLNode", 
                          "RXMLAbstractNode", "XMLAbstractNode", 
                          "oldClass")), forSale = structure(list(
                            name = "forSale", attributes = NULL, 
                            children = list(text = structure(list(
                              name = "text", attributes = NULL, 
                              children = NULL, namespace = NULL, 
                              namespaceDefinitions = NULL, value = "https://www.zillow.com/scituate-ma/"), class = c("XMLTextNode", 
                            "XMLNode", "RXMLAbstractNode", "XMLAbstractNode", 
                            "oldClass"))), namespace = NULL, 
                            namespaceDefinitions = NULL), class = c("XMLNode", 
                          "RXMLAbstractNode", "XMLAbstractNode", 
                          "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                        "RXMLAbstractNode", "XMLAbstractNode", 
                        "oldClass"))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                    "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                    ))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
                  "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
                  ))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
            "RXMLAbstractNode", "XMLAbstractNode", "oldClass"
            ))), namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
        "RXMLAbstractNode", "XMLAbstractNode", "oldClass"))), 
        namespace = NULL, namespaceDefinitions = NULL), class = c("XMLNode", 
    "RXMLAbstractNode", "XMLAbstractNode", "oldClass")))

Я ожидаю, что функция xmlValue выведет значение доллара "zestimate" (оценочная стоимость Zillow для любого данного дома), отображаемое в виде текста для элемента XML "amount" в ответе API.

Спасибо. Извините за неясность или неправильную терминологию!

17.06.2019

  • Можете ли вы также опубликовать содержимое reply. 17.06.2019
  • Правки @Theo выше 17.06.2019
  • Вам нужно проанализировать содержимое XML, а не весь список: doc = xmlTreeParse(reply$response, asText = TRUE, useInternal = TRUE) 17.06.2019
  • @Parfait Я попытался выполнить синтаксический анализ, используя как response$response, так и response$response (во втором случае, просто не назначая переменную response и пытаясь изолировать вывод XML от), и оба приводят к сообщению об ошибке Error in (if (isHTML ) предупреждение иначе стоп)(e) : плохое сообщение об ошибке 17.06.2019
  • Пожалуйста, dput(reply) в теле сообщения, так как в вашем образце могут отсутствовать уровни. 17.06.2019
  • Правки @Parfait выше 18.06.2019

Ответы:


1

Я начинаю с response, который является my_xml. По сути, аналогичные шаги должны привести вас к amount, даже если вы начнете с вашего xml.

library(tidyverse)
library(XML)

df_xml = xmlTreeParse(my_xml) 
df_root = xmlRoot(df_xml)

getNodeSet(df_root, "//amount") %>% unlist

С новыми данными dput работает следующее.

df = dput(result) # essentially your df=result
df1 = df$response # there are three items in the list and response holds the info
getNodeSet(df1, "//amount") %>% unlist # this gets you a dataframe
18.06.2019
  • Привет, Тео, я попробовал ваш метод, но все еще получаю сообщение об ошибке при попытке проанализировать ответ в первой строке кода. Это ошибка, которую я впервые получил при попытке решить эту проблему: Ошибка: XML-содержимое не похоже на XML.... Я думаю, проблема в том, что вывод вызова/ответа не является обычным XML-файлом, или, по крайней мере, он не может управляться в его текущем состоянии с помощью обычных функций XML R. Спасибо за помощь! 18.06.2019
  • В качестве примечания: я также попытался написать файл XML из ответа, предоставленного API; Я думал, что ответ может быть в форме фрейма данных, но когда я попытался это изменить, он выдал ошибку, говорящую, что ответ не является фреймом данных. Итак, если это в формате XML, но не в формате данных или XML-файле, что это? 18.06.2019
  • Новые материалы

    Как создать диаграмму градиентной кисти с помощью D3.js
    Резюме: Из этого туториала Вы узнаете, как добавить градиентную кисть к диаграмме с областями в D3.js. Мы добавим градиент к значениям SVG и применим градиент в качестве заливки к диаграмме с..

    Я хотел выучить язык программирования MVC4, но не мог выучить его раньше, потому что это выглядит сложно…
    Просто начните и учитесь самостоятельно Я хотел выучить язык программирования MVC4, но не мог выучить его раньше, потому что он кажется мне сложным, и я бросил его. Это в основном инструмент..

    Лицензии с открытым исходным кодом: руководство для разработчиков и создателей
    В динамичном мире разработки программного обеспечения открытый исходный код стал мощной парадигмой, способствующей сотрудничеству, инновациям и прогрессу, движимому сообществом. В основе..

    Объяснение документов 02: BERT
    BERT представил двухступенчатую структуру обучения: предварительное обучение и тонкая настройка. Во время предварительного обучения модель обучается на неразмеченных данных с помощью..

    Как проанализировать работу вашего классификатора?
    Не всегда просто знать, какие показатели использовать С развитием глубокого обучения все больше и больше людей учатся обучать свой первый классификатор. Но как только вы закончите..

    Работа с цепями Маркова, часть 4 (Машинное обучение)
    Нелинейные цепи Маркова с агрегатором и их приложения (arXiv) Автор : Бар Лайт Аннотация: Изучаются свойства подкласса случайных процессов, называемых дискретными нелинейными цепями Маркова..

    Crazy Laravel Livewire упростил мне создание электронной коммерции (панель администратора и API) [Часть 3]
    Как вы сегодня, ребята? В этой части мы создадим CRUD для данных о продукте. Думаю, в этой части я не буду слишком много делиться теорией, но чаще буду делиться своим кодом. Потому что..


    Для любых предложений по сайту: [email protected]