これが私が解析しようとしているXMLです:
val response = "<?xml version=\"1.0\" encoding=\"utf-8\"?><createCustomerProfileResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Error</resultCode><message><code>E00039</code><text>A duplicate record with ID 8386840 already exists.</text></message></messages><customerPaymentProfileIdList /><customerShippingAddressIdList /><validationDirectResponseList><string>1,1,1,This transaction has been approved.,0GR6L8,Y,2173844354,none,Test transaction for ValidateCustomerPaymentProfile.,0.00,CC,auth_only,,Test21,Rasmussen,,1234 test st,San Diego,CA,92107,,,,,none,none,none,none,none,none,none,none,0.00,0.00,0.00,FALSE,none,163C552C4DDDC440BAA35C76C47EB79D,,2,,,,,,,,,,,XXXX0027,Visa,,,,,,,,,,,,,,,,</string></validationDirectResponseList></createCustomerProfileResponse>"
これが私のコードです:
val source = Source.fromString(response)
val html = new HTML5Parser
val htmlObject = html.loadXML(source)
var resultCode = (htmlObject \ "createCustomerProfileResponse" \ "messages" \ "resultCode").text
resultCodeは常に空です。私は何が間違っているのですか?
編集:
応答XMLを更新しました。現在、ルートXMLは1つだけです。それでも機能しません。
また、html5Parserをmodels.html5Parserからhtml5Parserだけに変更しました。それでも機能しません。