剛開始學習xmlBean覺得非常好用,所以邊學習,邊開始整理一些應用,供留備.
在xmlbeans2.2\samples\OrderMatters有很多例子,我就是參照學習的^-^;
1,創建ServicesDocument
1 public static ServicesDocument parseXml(String filePath) throws Exception {
2 File file = new File(filePath);
3 ServicesDocument sd = null;
4 if (file.exists()) {
5 try {
6 sd = ServicesDocument.Factory.parse(file);
7 } catch (Exception e) {
8 throw new Exception(e.toString());
9 }
10 }
11 else{
12 sd = createServicesDocument();
13 }
14 return sd;
15 }
16
2 File file = new File(filePath);
3 ServicesDocument sd = null;
4 if (file.exists()) {
5 try {
6 sd = ServicesDocument.Factory.parse(file);
7 } catch (Exception e) {
8 throw new Exception(e.toString());
9 }
10 }
11 else{
12 sd = createServicesDocument();
13 }
14 return sd;
15 }
16
2,應用ServicesDocument可以取得你定義的xml對象節點進行操作
1)當你在xsd中定義了節點為maxOccurs="unbounded"時
1 Workflow[] wfs = ses.getWorkflowArray();
2 String pacId = workflow.getPackageDefId();
3 String proDefId = workflow.getProcessDefId();
4 String actDefID = workflow.getActivityDefId();
5 for (int i = 0; i < wfs.length; i++) {
6 Workflow existWorkflow = wfs[i];
7 if (pacId.equals(existWorkflow.getPackageDefId())
8 && proDefId.equals(existWorkflow.getProcessDefId())
9 && actDefID.equals(existWorkflow.getActivityDefId())) {
10 ses.removeWorkflow(i);
11 break;
12 }
13 }
2 String pacId = workflow.getPackageDefId();
3 String proDefId = workflow.getProcessDefId();
4 String actDefID = workflow.getActivityDefId();
5 for (int i = 0; i < wfs.length; i++) {
6 Workflow existWorkflow = wfs[i];
7 if (pacId.equals(existWorkflow.getPackageDefId())
8 && proDefId.equals(existWorkflow.getProcessDefId())
9 && actDefID.equals(existWorkflow.getActivityDefId())) {
10 ses.removeWorkflow(i);
11 break;
12 }
13 }