R에서 XML 패키지를 사용하여 네임 스페이스로 XML 구문 분석

프리 야

XMLR 패키지를 사용하여 xml 파일을 구문 분석하려고합니다 . 샘플 XML 콘텐츠는 다음과 같습니다.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header>
      <messageContext xmlns="http://www.deltavista.com/dspone/ordercheck-if/V001">
         <credentials>
            <user>foobar</user>
            <password>barbaz</password>
         </credentials>
      </messageContext>
   </soapenv:Header>
   <soapenv:Body>
      <ns1:orderCheckResponse xmlns:ns1="http://www.deltavista.com/dspone/ordercheck-if/V001">
         <ns1:returnCode>1</ns1:returnCode>
         <ns1:product>
            <ns1:name>Consumer</ns1:name>
            <ns1:country>POL</ns1:country>
            <ns1:language>POL</ns1:language>
         </ns1:product>
         <ns1:archiveID>420</ns1:archiveID>
         <ns1:reportCreationTime>201911151220</ns1:reportCreationTime>
         <ns1:foundAddress>
            <ns1:legalForm>PERSON</ns1:legalForm>
            <ns1:address>
               <ns1:name>John</ns1:name>
               <ns1:firstName>Dow</ns1:firstName>
               <ns1:gender>MALE</ns1:gender>
               <ns1:dateOfBirth>19960410</ns1:dateOfBirth>
               <ns1:location>
                  <ns1:street>nowhere</ns1:street>
                  <ns1:house>48</ns1:house>
                  <ns1:city>farfarland</ns1:city>
                  <ns1:zip>00-500</ns1:zip>
                  <ns1:country>POL</ns1:country>
               </ns1:location>
            </ns1:address>
         </ns1:foundAddress>
         <ns1:myDecision>
            <ns1:decision>YELLOW</ns1:decision>
         </ns1:myDecision>
         <ns1:personBasicData>
            <ns1:knownSince>20181201</ns1:knownSince>
            <ns1:contact>
               <ns1:item>EMAIL</ns1:item>
               <ns1:value>[email protected]</ns1:value>
            </ns1:contact>
            <ns1:contact>
               <ns1:item>PHONE</ns1:item>
               <ns1:value>123456789</ns1:value>
            </ns1:contact>
         </ns1:personBasicData>
         <ns1:decisionMatrix>
            <ns1:identificationDecision>
               <ns1:personStatus xsi:type="ns1:DecisionMatrixItemPersonStatus" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <ns1:partialDecision>GREEN</ns1:partialDecision>
                  <ns1:value>ADULT</ns1:value>
               </ns1:personStatus>
               <ns1:identificationType xsi:type="ns1:DecisionMatrixItemIdentificationType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <ns1:partialDecision>GREEN</ns1:partialDecision>
                  <ns1:value>IDENTITY_IN_CITY</ns1:value>
               </ns1:identificationType>
               <ns1:similarHit xsi:type="ns1:DecisionMatrixItemInt" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <ns1:partialDecision>GREEN</ns1:partialDecision>
                  <ns1:value>0</ns1:value>
               </ns1:similarHit>
               <ns1:houseType xsi:type="ns1:DecisionMatrixItemString" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <ns1:partialDecision>GREEN</ns1:partialDecision>
                  <ns1:value>SHARED_USAGE</ns1:value>
               </ns1:houseType>
               <ns1:nameHint xsi:type="ns1:DecisionMatrixItemNameHint" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <ns1:partialDecision>GREEN</ns1:partialDecision>
                  <ns1:value>CONFIRMED</ns1:value>
               </ns1:nameHint>
               <ns1:locationIdentificationType xsi:type="ns1:DecisionMatrixItemLocationIdentificationType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <ns1:partialDecision>GREEN</ns1:partialDecision>
                  <ns1:value>HOUSE_CONFIRMED</ns1:value>
               </ns1:locationIdentificationType>
            </ns1:identificationDecision>
            <ns1:solvencyDecision>
               <ns1:paymentExperience xsi:type="ns1:DecisionMatrixItemPHS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <ns1:partialDecision>GREEN</ns1:partialDecision>
                  <ns1:value>NOPROBLEM</ns1:value>
               </ns1:paymentExperience>
               <ns1:externalSourcesProcessingStatus xsi:type="ns1:DecisionMatrixItemExternalProcessingStatus" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <ns1:partialDecision>GREEN</ns1:partialDecision>
                  <ns1:value>OK</ns1:value>
               </ns1:externalSourcesProcessingStatus>
            </ns1:solvencyDecision>
            <ns1:clientExtensionsDecision>
               <ns1:applicationFilter xsi:type="ns1:DecisionMatrixItemStringWithOverride" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <ns1:partialDecision>GREEN</ns1:partialDecision>
                  <ns1:value>0</ns1:value>
               </ns1:applicationFilter>
               <ns1:myScore xsi:type="ns1:DecisionMatrixItemInt" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <ns1:partialDecision>YELLOW</ns1:partialDecision>
                  <ns1:value>401</ns1:value>
               </ns1:myScore>
            </ns1:clientExtensionsDecision>
         </ns1:decisionMatrix>
         <ns1:paymentHistory>
            <ns1:currency>PLN</ns1:currency>
            <ns1:count>0</ns1:count>
            <ns1:dateOfLastEntry>20191111</ns1:dateOfLastEntry>
            <ns1:amountTotal>0.0</ns1:amountTotal>
            <ns1:amountTotalOpen>0.0</ns1:amountTotalOpen>
            <ns1:creditStatusMax>0</ns1:creditStatusMax>
            <ns1:masterRiskStatus>Brak danych o negatywnej historii</ns1:masterRiskStatus>
         </ns1:paymentHistory>
         <ns1:normalization>
            <ns1:searchedAddress xsi:type="ns1:SearchedAddressN" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <ns1:name>John</ns1:name>
               <ns1:firstName>Dow</ns1:firstName>
               <ns1:gender>MALE</ns1:gender>
               <ns1:dateOfBirth>19960410</ns1:dateOfBirth>
               <ns1:location>
                  <ns1:street>nowhere</ns1:street>
                  <ns1:house>39</ns1:house>
                  <ns1:houseExtension/>
                  <ns1:city>farfarland</ns1:city>
                  <ns1:zip>00-500</ns1:zip>
                  <ns1:country>POL</ns1:country>
               </ns1:location>
               <ns1:addressID>123</ns1:addressID>
               <ns1:unitID>123</ns1:unitID>
               <ns1:liableID>1231</ns1:liableID>
               <ns1:houseID>1232</ns1:houseID>
               <ns1:streetID>1233</ns1:streetID>
               <ns1:cityID>1234</ns1:cityID>
            </ns1:searchedAddress>
            <ns1:foundAddress>
               <ns1:addressID>1235</ns1:addressID>
               <ns1:unitID>1236</ns1:unitID>
               <ns1:liableID>1237</ns1:liableID>
               <ns1:houseID>1238</ns1:houseID>
               <ns1:streetID>1239</ns1:streetID>
               <ns1:cityID>1230</ns1:cityID>
            </ns1:foundAddress>
         </ns1:normalization>
         <ns1:clientExtensions>
            <ns1:additionalData>
               <ns1:name>pesel_verification_status</ns1:name>
               <ns1:value>1</ns1:value>
            </ns1:additionalData>
            <ns1:additionalData>
               <ns1:name>pesel_verification_execution_code</ns1:name>
               <ns1:value>200</ns1:value>
            </ns1:additionalData>
            <ns1:additionalData>
               <ns1:name>pesel_verification_codes</ns1:name>
               <ns1:value>12010; 12013</ns1:value>
            </ns1:additionalData>
         </ns1:clientExtensions>
         <ns1:executionStrategy/>
      </ns1:orderCheckResponse>
   </soapenv:Body>
</soapenv:Envelope>

다음은이 XML 콘텐츠를 읽고 구문 분석하는 데 사용하는 코드입니다. str금후:

library(XML)
foobar <- xmlInternalTreeParse(str, encoding = 'KOI8-R', useInternalNodes = F)
xmlSApply(foobar$doc$children$Envelope, function(x) xmlSApply(x, names))
xmlSApply(foobar$doc$children$Envelope, function(x) xmlSApply(x, function(x1) xmlSApply(x1, names)))

여기에서 XML 콘텐츠를 구문 분석하고 노드를 반복하여 최소한 이름을 인쇄 할 수 있습니다. 그러나 나는 많은 질문을 읽고 xPathApply()등을 사용하여 수많은 조합을 시도했지만 내부의 값을 추출 할 수 없었습니다 . ( 참조 )

내가 여기서 뭘 잘못하고 있는지에 대한 힌트.

완전한

//*네임 스페이스를 인식하여 모든 요소 이름과 값을 검색 하는 간단한 하위 XPath 검색을 고려하십시오 . 그러나 XPath는 네임 스페이스 접두사를 참조하지 않으므로이 특정 검색의 경우 xpathSApply호출 에서 중복됩니다 .

doc <- xmlParse(str, asText=TRUE)

nmsp <- c(soapenv = "http://schemas.xmlsoap.org/soap/envelope/",
          doc = "http://www.deltavista.com/dspone/ordercheck-if/V001",
          ns1 = "http://www.deltavista.com/dspone/ordercheck-if/V001")

# NAMED CHARACTER VECTOR OF ALL 117 ELEMENT NAMES AND VALUES
elem_vals <- setNames(xpathSApply(doc, path="//*", namespaces = nmsp, xmlValue) ,
                      xpathSApply(doc, path="//*", namespaces = nmsp, xmlName))

산출

이름 (처음 20 개 항목)

head(names(elem_vals), 20)
#  [1] "Envelope"           "Header"             "messageContext"     "credentials"        "user"              
#  [6] "password"           "Body"               "orderCheckResponse" "returnCode"         "product"           
# [11] "name"               "country"            "language"           "archiveID"          "reportCreationTime"
# [16] "foundAddress"       "legalForm"          "address"            "name"               "firstName"   

(최근 20 개 항목)

tail(elem_vals, 20)    
# streetID                                                                                                                          cityID 
# "1233"                                                                                                                            "1234" 
# foundAddress                                                                                                                   addressID 
# "123512361237123812391230"                                                                                                        "1235" 
# unitID                                                                                                                         liableID 
# "1236"                                                                                                                            "1237" 
# houseID                                                                                                                         streetID 
# "1238"                                                                                                                            "1239" 
# cityID                                                                                                                  clientExtensions 
# "1230"                              "pesel_verification_status1pesel_verification_execution_code200pesel_verification_codes12010; 12013" 
# additionalData                                                                                                                      name 
# "pesel_verification_status1"                                                                                 "pesel_verification_status" 
# value                                                                                                                     additionalData 
# "1"                                                                                               "pesel_verification_execution_code200" 
# name                                                                                                                               value 
# "pesel_verification_execution_code"                                                                                                "200" 
# additionalData                                                                                                                      name 
# "pesel_verification_codes12010; 12013"                                                                        "pesel_verification_codes" 
# value                                                                                                                 executionStrategy 
# "12010; 12013"                                                                                                                       "" 

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Python에서 ElementTree를 사용하여 네임 스페이스로 XML 구문 분석

분류에서Dev

XMLLINT 및 BASH를 사용하여 XML 파일에서 네임 스페이스를 구문 분석하는 방법

분류에서Dev

네임 스페이스를 사용하여 XML에서 데이터 구문 분석

분류에서Dev

네임 스페이스가있는 R을 사용하여 XML 구문 분석

분류에서Dev

PLSQL에서 네임 스페이스를 사용하여 중첩 된 XML 구문 분석

분류에서Dev

네임 스페이스를 사용하여 SOAP xml 구문 분석

분류에서Dev

lxml을 사용하여 xml을 구문 분석 할 때 태그에 네임 스페이스 접두사 유지

분류에서Dev

DOM을 사용하여 네임 스페이스로 XML 구문 분석

분류에서Dev

요소 및 네임 스페이스를 사용하여 Pandas로 XML 구문 분석 속도 향상

분류에서Dev

Python lxml을 사용하여 네임 스페이스가있는 XML 문서 구문 분석 문제

분류에서Dev

j 쿼리를 사용하여 네임 스페이스가있는 xml 파일 구문 분석

분류에서Dev

R에서 중첩 된 XML (네임 스페이스 포함) 구문 분석

분류에서Dev

JQuery를 사용하여 네임 스페이스로 xml을 구문 분석하는 방법 (및 모든 브라우저 ..)?

분류에서Dev

네임 스페이스 정보로 XML 구문 분석

분류에서Dev

네임 스페이스로 XML 응답 구문 분석

분류에서Dev

네임 스페이스로 XML 파일 구문 분석

분류에서Dev

SQL 쿼리에서 여러 네임 스페이스 XML을 구문 분석하는 방법

분류에서Dev

PHP에서 네임 스페이스를 사용하여 XML 문서 생성

분류에서Dev

C #을 사용하여 여러 네임 스페이스가있는 Xml 구문 분석

분류에서Dev

Python 3x : python xml.etree를 사용하여 네임 스페이스가있는 xml 파일 구문 분석

분류에서Dev

lxml을 사용하여 중첩 된 네임 스페이스가있는 XML 속성 구문 분석

분류에서Dev

Java에서 특정 스키마를 사용하여 XML 구문 분석 오류

분류에서Dev

선언되지 않은 네임 스페이스 자바 구문 분석 XML

분류에서Dev

네임 스페이스가있는 xml 구문 분석 문제

분류에서Dev

XDocument를 사용하여 XML을 구문 분석하는 동안 네임 스페이스를 확인할 수 없습니다.

분류에서Dev

XML 문서를 사용할 때 네임 스페이스 지정

분류에서Dev

rentrez를 사용하여 R에서 XML 파일 구문 분석

분류에서Dev

JSON / XML 속성에서 여러 네임 스페이스 구분 기호를 사용할 수 있습니까?

분류에서Dev

XML 스키마를 사용하여 List <String>을 XML로 구문 분석

Related 관련 기사

  1. 1

    Python에서 ElementTree를 사용하여 네임 스페이스로 XML 구문 분석

  2. 2

    XMLLINT 및 BASH를 사용하여 XML 파일에서 네임 스페이스를 구문 분석하는 방법

  3. 3

    네임 스페이스를 사용하여 XML에서 데이터 구문 분석

  4. 4

    네임 스페이스가있는 R을 사용하여 XML 구문 분석

  5. 5

    PLSQL에서 네임 스페이스를 사용하여 중첩 된 XML 구문 분석

  6. 6

    네임 스페이스를 사용하여 SOAP xml 구문 분석

  7. 7

    lxml을 사용하여 xml을 구문 분석 할 때 태그에 네임 스페이스 접두사 유지

  8. 8

    DOM을 사용하여 네임 스페이스로 XML 구문 분석

  9. 9

    요소 및 네임 스페이스를 사용하여 Pandas로 XML 구문 분석 속도 향상

  10. 10

    Python lxml을 사용하여 네임 스페이스가있는 XML 문서 구문 분석 문제

  11. 11

    j 쿼리를 사용하여 네임 스페이스가있는 xml 파일 구문 분석

  12. 12

    R에서 중첩 된 XML (네임 스페이스 포함) 구문 분석

  13. 13

    JQuery를 사용하여 네임 스페이스로 xml을 구문 분석하는 방법 (및 모든 브라우저 ..)?

  14. 14

    네임 스페이스 정보로 XML 구문 분석

  15. 15

    네임 스페이스로 XML 응답 구문 분석

  16. 16

    네임 스페이스로 XML 파일 구문 분석

  17. 17

    SQL 쿼리에서 여러 네임 스페이스 XML을 구문 분석하는 방법

  18. 18

    PHP에서 네임 스페이스를 사용하여 XML 문서 생성

  19. 19

    C #을 사용하여 여러 네임 스페이스가있는 Xml 구문 분석

  20. 20

    Python 3x : python xml.etree를 사용하여 네임 스페이스가있는 xml 파일 구문 분석

  21. 21

    lxml을 사용하여 중첩 된 네임 스페이스가있는 XML 속성 구문 분석

  22. 22

    Java에서 특정 스키마를 사용하여 XML 구문 분석 오류

  23. 23

    선언되지 않은 네임 스페이스 자바 구문 분석 XML

  24. 24

    네임 스페이스가있는 xml 구문 분석 문제

  25. 25

    XDocument를 사용하여 XML을 구문 분석하는 동안 네임 스페이스를 확인할 수 없습니다.

  26. 26

    XML 문서를 사용할 때 네임 스페이스 지정

  27. 27

    rentrez를 사용하여 R에서 XML 파일 구문 분석

  28. 28

    JSON / XML 속성에서 여러 네임 스페이스 구분 기호를 사용할 수 있습니까?

  29. 29

    XML 스키마를 사용하여 List <String>을 XML로 구문 분석

뜨겁다태그

보관