我正在尝试从流中解析来自我们的在线支付网关处理器的XML网关响应。然后采用这些变量来更新各种联系,机会和交易记录。 我正在努力从XML中获取值
我只是对XML解析了解不多,所以我试图先获取需要返回的值,然后担心可以通过@invocablemethod重试它们。
String trans = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><DirectPaymentResponse xmlns="https://api.ewaypaymentscom/"><DirectPaymentResult><AuthorisationCode>0000C</AuthorisationCode><ResponseCode>00</ResponseCode><ResponseMessage>A2000</ResponseMessage><TransactionID>0000003</TransactionID><TransactionStatus>true</TransactionStatus><TransactionType>MOTO</TransactionType><BeagleScore>0.6</BeagleScore><Verification><CVN>Unchecked</CVN><Address>Unchecked</Address><Email>Unchecked</Email><Mobile>Unchecked</Mobile><Phone>Unchecked</Phone></Verification><Customer><TokenCustomerID>66666666</TokenCustomerID><Reference>Reference</Reference><Title>Mr.</Title><FirstName>aan</FirstName><LastName>McDat</LastName><CompanyName>Perkins</CompanyName><JobDescription>Officer</JobDescription><Street1>23 Verdun Street</Street1><Street2 /><City>Nedlands</City><State>WA</State><PostalCode>6009</PostalCode><Country>au</Country><Email>t@perkins.org.au</Email><Phone>0811111111</Phone><Mobile>0422222222</Mobile><Comments>Hi there</Comments><Fax /><Url>perkins.org.au</Url><CardDetails><Number>452012XXXXX9</Number><Name>ASd estt</Name><ExpiryMonth>1</ExpiryMonth><ExpiryYear>19</ExpiryYear><StartMonth /><StartYear /><IssueNumber /><CVN /></CardDetails></Customer><Payment><TotalAmount>200</TotalAmount><InvoiceNumber>0067F00000UmnAJ</InvoiceNumber><InvoiceDescription /><InvoiceReference /><CurrencyCode>AUD</CurrencyCode></Payment></DirectPaymentResult></DirectPaymentResponse></soap:Body></soap:Envelope>';
上面是我收到的字符串
Dom.Document doc = new Dom.Document();
Doc.load(trans);
然后我研究节点以尝试获得值。
Dom.XmlNode Env = doc.getRootElement();
system.debug('Root Element'+doc.getRootElement());
Dom.XmlNode body = Env.getChildElement('Body', 'http://www.w3.org/2003/05/soap-envelope');
system.debug('Child Element'+Env.getChildElement('Body', 'http://www.w3.org/2003/05/soap-envelope'));
List<Dom.XmlNode> cElements = Env.getChildElements();
system.debug('Child Elements'+Env.getChildElements());
Dom.XmlNode DirectPR = body.getChildElement('DirectPaymentResponse','https://api.ewaypaymentscom/');
system.debug('DirectPR'+body.getChildElement('DirectPaymentResponse','https://api.ewaypaymentscom/'));
Dom.XmlNode DirectPResult = DirectPR.getChildElement('DirectPaymentResult','https://api.ewaypaymentscom/');
system.debug('Direct Payment Results'+DirectPR.getChildElement('DirectPaymentResult','https://api.ewaypaymentscom/'));
Dom.XmlNode AuthCodes = DirectPResult.getChildElement('AuthorisationCode', 'https://api.ewaypaymentscom/');
system.debug('Auth Element '+DirectPResult.getChildElement('AuthorisationCode', 'https://api.ewaypaymentscom/'));
Dom.XmlNode AUText = AuthCodes.getChildElement('Text', 'https://api.ewaypaymentscom/');
system.debug('Auth Element '+AuthCodes.getChildElement('Text', 'https://api.ewaypaymentscom/'));
String Conde = AuthCodes.getAttributeValue('AuthorisationCode', 'https://api.ewaypaymentscom/');
system.debug('Auth Code; '+AuthCodes.getAttributeValue('AuthorisationCode', 'https://api.ewaypaymentscom/'));`
我试图返回值,但一直得到“发生错误:发生了Apex错误:System.NullPointerException:尝试取消引用空对象” 还有一点 'System.XmlException:在开始标记之前仅允许空白内容,而不是{' 但无法复制该问题。 请注意,我已经从“ api.ewaypaymentscom”中删除了点,因为它只允许我包含10。如果我从getChildElement方法中删除了它们,则仅返回null。 目前,我正在使用execute anon窗口来测试代码,但想在可调用的方法类中使用它。
答案 0 :(得分:0)
我明白了, 我可以通过
拉取值string AuthcodeTXT = AuthCodes.getText();
system.debug('Auth Code Text: '+ AuthCodes.getText());
它返回'0000C'