在Salesforce中处理Xml的生成与解析
在Salesforce中处理Xml的生成与解析
1): Generate Xml
private String ConvertAccountToXmlInfo(Account acc){ Dom.Document doc = new Dom.Document();
Dom.Xmlnode rootNode = doc.createRootElement('Accounts', null, null); Dom.Xmlnode accountNode = rootNode.addChildElement('Account', null, null);
accountNode.addChildElement('AccountName', null, null).addTextNode(acc.Name);
accountNode.addChildElement('AccountNumber', null, null).addTextNode(acc.AccountNumber);
accountNode.addChildElement('ABN', null, null).addTextNode(acc.ABN__c);
accountNode.addChildElement('AutoEmailInvoice', null, null).addTextNode(String.valueOf(acc.Auto_Email_Invoice__c));
accountNode.addChildElement('CreditType', null, null).addTextNode(acc.Credit_Type__c);
accountNode.addChildElement('GPID', null, null).addTextNode(acc.GP_ID__c);
accountNode.addChildElement('PPSR', null, null).addTextNode(acc.PPSR__c);
accountNode.addChildElement('VIPNumber', null, null).addTextNode(acc.VIP_Number__c);
accountNode.addChildElement('AccountContact', null, null).addTextNode(acc.Account_Contact__c);
accountNode.addChildElement('Phone', null, null).addTextNode(acc.Phone);
accountNode.addChildElement('Fax', null, null).addTextNode(acc.Fax);
accountNode.addChildElement('Email', null, null).addTextNode(acc.Email__c); Dom.Xmlnode baNode = accountNode.addChildElement('BillingAddress', null, null);
baNode.addChildElement('Address', null, null).addTextNode(acc.BillingStreet);
baNode.addChildElement('Suburb', null, null).addTextNode(acc.BillingCity);
baNode.addChildElement('Postcode', null, null).addTextNode(acc.BillingPostalCode);
baNode.addChildElement('State', null, null).addTextNode(acc.BillingState);
baNode.addChildElement('Country', null, null).addTextNode(acc.BillingCountry); Dom.Xmlnode saNode = accountNode.addChildElement('ShippingAddress', null, null);
saNode.addChildElement('Address', null, null).addTextNode(acc.ShippingStreet);
saNode.addChildElement('Suburb', null, null).addTextNode(acc.ShippingCity);
saNode.addChildElement('Postcode', null, null).addTextNode(acc.ShippingPostalCode);
saNode.addChildElement('State', null, null).addTextNode(acc.ShippingState);
saNode.addChildElement('Country', null, null).addTextNode(acc.ShippingCountry); return doc.toXmlString();
}
2): Parse Xml
private static Account GenerateAccountFromXmlInfo(String accountXmlInfo){
Account currentAcc = new Account();
system.debug('00001 ---- ' + accountXmlInfo);
Dom.Document doc = new Dom.Document();
doc.load(accountXmlInfo);
Dom.Xmlnode rootNode = doc.getRootElement();
Dom.Xmlnode accountNode = rootNode.getChildElement('Account', null);
currentAcc.Name = accountNode.getChildElement('AccountName', null).getText();
currentAcc.AccountNumber = accountNode.getChildElement('AccountNumber', null).getText();
currentAcc.ABN__c = accountNode.getChildElement('ABN', null).getText();
currentAcc.Auto_Email_Invoice__c = Boolean.valueOf(accountNode.getChildElement('AutoEmailInvoice', null).getText());
currentAcc.Credit_Type__c = accountNode.getChildElement('CreditType', null).getText();
currentAcc.GP_ID__c = accountNode.getChildElement('GPID', null).getText();
currentAcc.PPSR__c = accountNode.getChildElement('PPSR', null).getText();
currentAcc.VIP_Number__c = accountNode.getChildElement('VIPNumber', null).getText();
currentAcc.Account_Contact__c = accountNode.getChildElement('AccountContact', null).getText();
currentAcc.Phone = accountNode.getChildElement('Phone', null).getText();
currentAcc.Fax = accountNode.getChildElement('Fax', null).getText();
currentAcc.Email__c = accountNode.getChildElement('Email', null).getText(); Dom.Xmlnode baNode = accountNode.getChildElement('BillingAddress', null);
currentAcc.BillingStreet = baNode.getChildElement('Address', null).getText();
currentAcc.BillingCity = baNode.getChildElement('Suburb', null).getText();
currentAcc.BillingPostalCode = baNode.getChildElement('Postcode', null).getText();
currentAcc.BillingState = baNode.getChildElement('State', null).getText();
currentAcc.BillingCountry = baNode.getChildElement('Country', null).getText(); Dom.Xmlnode saNode = accountNode.getChildElement('ShippingAddress', null);
currentAcc.ShippingStreet = saNode.getChildElement('Address', null).getText();
currentAcc.ShippingCity = saNode.getChildElement('Suburb', null).getText();
currentAcc.ShippingPostalCode = saNode.getChildElement('Postcode', null).getText();
currentAcc.ShippingState = saNode.getChildElement('State', null).getText();
currentAcc.ShippingCountry = saNode.getChildElement('Country', null).getText(); return currentAcc;
}
Click following links to learn more technology:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_xml_dom.htm
在Salesforce中处理Xml的生成与解析的更多相关文章
- 6.2 dubbo在spring中自定义xml标签源码解析
在6.1 如何在spring中自定义xml标签中我们看到了在spring中自定义xml标签的方式.dubbo也是这样来实现的. 一 META_INF/dubbo.xsd 比较长,只列出<dubb ...
- 在请求中使用XML Publisher生成文件报错
在页面上使用按钮生成该文件不报错,但是使用请求就报错. 错误内容如下 Error : No corresponding LOB data found :SELECT L.FILE_DATA FILE_ ...
- xml的生成与解析_老师笔记
使用序列化器生成一个xml文件 //1,初始化一个xml文件的序列化器 XmlSerializer serializer = Xml.newSerializer(); //2.初始化序列器参数 Fil ...
- Java读取数据库中的xml格式内容,解析后修改属性节点内容并写回数据库
直接附代码: 1.测试用的xml内容 <mxGraphModel> <root> <mxCell id="-1" /> <mxCell i ...
- android xml的生成与解析
Main java package com.itheima.xml; import android.app.Activity; import android.content.Context; impo ...
- Qt之JSON生成与解析
JSON(JavaScript Object Notation)是一种轻量级的数据交换格式.它基于JavaScript(Standard ECMA-262 3rd Edition - December ...
- ZXing 生成、解析二维码图片的小示例
概述 ZXing 是一个开源 Java 类库用于解析多种格式的 1D/2D 条形码.目标是能够对QR编码.Data Matrix.UPC的1D条形码进行解码. 其提供了多种平台下的客户端包括:J2ME ...
- 【转载】Qt之JSON生成与解析
JSON(JavaScript Object Notation)是一种轻量级的数据交换格式.它基于JavaScript(Standard ECMA-262 3rd Edition - December ...
- Android中XML文件的序列化生成与解析
xml文件是非常常用的,在android中json和xml是非常常用的两种封装数据的形式,从服务器中获取数据也经常是这两种形式的,所以学会生成和解析xml和json是非常有用的,json相对来说是比较 ...
随机推荐
- 【leetcode】Restore IP Addresses
Restore IP Addresses Given a string containing only digits, restore it by returning all possible val ...
- 解读Unity中的CG编写Shader系列八(镜面反射)
转自http://www.itnose.net/detail/6117378.html 讨论完漫反射之后,接下来肯定就是镜面反射了 在开始镜面反射shader的coding之前,要扩充一下前面提到的知 ...
- ACM/ICPC 之 暴力打表(求解欧拉回路)-编码(POJ1780)
///找到一个数字序列包含所有n位数(连续)一次且仅一次 ///暴力打表 ///Time:141Ms Memory:2260K #include<iostream> #include< ...
- Silverlight 动画性能
通过几个配置可以提高动画性能: Desired Frame Rate 在WEB项目中配置: <div id="silverlightControlHost"> < ...
- php继承、多态
继承: 概念:子类可以继承父类的一切 特点:单继承:一个子类只能有一个父类,一个父类可以派生出多个子类 方法重写:在子类里面对父类的方法进行重写. 重写:override 重载,编译多态:overlo ...
- php生成对象的研究
<?php abstract class E{ protected $name; function __construct($name){ $this->name = $name; } a ...
- osg osgDB::Options noTexturesInIVEFile ForceReadingImage dds_flip
osgDB::writeNodeFile(node, path, new osgDB::Options("noTexturesInIVEFile")); noTexturesInI ...
- Target runtime Apache Tomcat v6.0 is not defined.错误解决方法
一.背景 最近在使用本地的tomcat进行运行项目的时候,发现出现了如题所述的问题.不知道什么原因,经过努力解决了该问题. 二.解决步骤 右击项目---选择属性---选择targeted runtim ...
- [Android Pro] Android以root起一个process[shell脚本的方法]
reference to : http://***/Article/11768 有时候我们写的app要用uid=0的方式启动一个process,framework层和app层是做不到的,只有通过写脚 ...
- October 7th 2016 Week 41st Friday
The land didn't move, but moved; the sea was not still, yet was still. 大地止而亦行,大海动而亦静. Remember that ...