在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相对来说是比较 ...
随机推荐
- Linux安装字体
用惯了Win7的字体,感觉雅黑看着很舒服,就动手在Linux安装下,简单描述下: 第一步:百度一下,找到微软雅黑字体(.ttf)下载 第二步:把下载的字体放到cd /usr/share/fonts/z ...
- mysql性能优化学习笔记-存储引擎
mysql体系架构 客户端(java.php.python等) mysql服务层(连接管理器.查询解析器.查询优化器.查询缓存) mysql存储引擎(innodb.myisam等) 存储引擎针对表而言 ...
- ios bitcode 机制对 dsym 调试文件的影响
今天想试试用dsym和crash文件跟踪crash信息,可是一直返回如下信息: Thread name: Dispatch queue: com.apple.main-thread Thread Cr ...
- [Linux]centOS7下RPM安装Perl
1.下载rpm依赖包,依照顺序安装. perl-parent-0.225-244.el7.noarch perl-HTTP-Tiny-0.033-3.el7.noarch perl-podla ...
- ACM/ICPC 之 DP-整数划分问题初探 (POJ1221)
写下这道题的原因很简单= =,因为这一题的状态转移方程不好找,另一方面,我看到很多针对这一题写的解题报告都把累加状态说得模棱两可,甚至直接说成了一个单一状态,弄得本是菜鸟的我硬生生折磨了一上午画了几个 ...
- algorithm 中的常用函数
非修改性序列操作(12个) 循环 对序列中的每个元素执行某操作 for_each() 查找 在序列中找出某个值的第一次出现的位置 fin ...
- Quartz 使用
public class IndexJob:IJob//此处必须实现 IJob接口 { /// <summary> /// 具体的任务 /// </summary> /// & ...
- 【leetcode】Minimum Depth of Binary Tree (easy)
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- IOS - 真机测试
转:版权声明:本文由本人亲自一步步完成,并细心排版生成,望广大同仁尊重一下本人的劳动成果,转载请注明出处,原文地址http://my.oschina.net/joanfen/blog/167730 一 ...
- C++静态代码分析工具对比cppCheck与PreFast
具体内容参看文件<CppCheck和PreFast对Cplusplus代码静态分析测试.zip> C++测试源代码main.cpp #define NULL 0 #include < ...