定义XML 数据:
<USER>
<ACCNAME>xiaoyw</ACCNAME>
<USERNAME>陈YY</USERNAME>
<ACCCODE>101</ACCCODE>
</USER>
<TENANTUSER>
<U_TENANTACCOUNT>manager</U_TENANTACCOUNT>
<U_TENANTNAME>项目经理</U_TENANTNAME>
<U_TENANTDN>o=harbin,cn=cordys,cn=expense,o=HL.CHINAUNICOM.CN</U_TENANTDN>
</TENANTUSER>
<TENANTUSER>
<U_TENANTACCOUNT>programer</U_TENANTACCOUNT>
<U_TENANTNAME>程序员</U_TENANTNAME>
<U_TENANTDN>o=harbin,cn=cordys,cn=expense,o=HL.CHINAUNICOM.CN</U_TENANTDN>
</TENANTUSER>
测试请求
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<CreateUser xmlns="http://schemas.cordys.com/XiaoywWSAppServerPackage" preserveSpace="no" qAccess="0" qValues="">
<v_user>
<USER>
<ACCNAME>xiaoyw</ACCNAME>
<USERNAME>陈YY</USERNAME>
<ACCCODE>101</ACCCODE>
</USER>
<TENANTUSER>
<U_TENANTACCOUNT>manager</U_TENANTACCOUNT>
<U_TENANTNAME>项目经理</U_TENANTNAME>
<U_TENANTDN>o=harbin,cn=cordys,cn=expense,o=HL.CHINAUNICOM.CN</U_TENANTDN>
</TENANTUSER>
<TENANTUSER>
<U_TENANTACCOUNT>programer</U_TENANTACCOUNT>
<U_TENANTNAME>程序员</U_TENANTNAME>
<U_TENANTDN>o=harbin,cn=cordys,cn=expense,o=HL.CHINAUNICOM.CN</U_TENANTDN>
</TENANTUSER>
</v_user>
</CreateUser>
</SOAP:Body>
</SOAP:Envelope>
Java 操作 XML
<pre name="code" class="java"> public static void createUser(int v_user)
{
BSF.startTransaction();
long acc_id =0;
int accountXML = XPath.getFirstMatch("*[local-name()='USER']", null, v_user);
String accountName = Node.getDataWithDefault(XPath.getFirstMatch("*[local-name()='ACCNAME']", null, accountXML), "");
String userName = Node.getDataWithDefault(XPath.getFirstMatch("*[local-name()='USERNAME']", null, accountXML), "");
String accountCode = Node.getDataWithDefault(XPath.getFirstMatch("*[local-name()='ACCCODE']", null, accountXML), "");
sm_account ACCOUNT = new sm_account(BusObjectConfig.TRANSIENT);
try
{
ACCOUNT.setAcc_code(accountCode);
ACCOUNT.setAcc_name(accountName);
ACCOUNT.setUser_name(userName);
ACCOUNT.setIs_admin((short)0);
ACCOUNT.insert();
BSF.commitTransaction();
} catch (Exception e)
{
e.printStackTrace();
BSF.abortTransaction();
return;
}
finally
{
if (accountXML != 0)
{
Node.delete(accountXML);
accountXML = 0;
}
}
acc_id = ACCOUNT.getAcc_id();
BSF.startTransaction();
sm_auth_account AUTH_ACC = new sm_auth_account(BusObjectConfig.TRANSIENT);
try
{
AUTH_ACC.setAcc_id(acc_id);
AUTH_ACC.setAuth_account(accountName);
AUTH_ACC.insert();
BSF.commitTransaction();
} catch (Exception e)
{
e.printStackTrace();
BSF.abortTransaction();
return;
}
int[] usersXML = XPath.getMatchingNodes("*[local-name()='TENANTUSER']", null, v_user);
for(int userXML:usersXML)
{
BSF.startTransaction();
sm_tenant_account Tenant_Account = new sm_tenant_account(BusObjectConfig.TRANSIENT);
Tenant_Account.setAcc_id(acc_id);
Tenant_Account.setTenant_account(Node.getDataWithDefault(XPath.getFirstMatch("*[local-name()='U_TENANTACCOUNT']", null, userXML), ""));
Tenant_Account.setTenant_name(Node.getDataWithDefault(XPath.getFirstMatch("*[local-name()='U_TENANTNAME']", null, userXML), ""));
Tenant_Account.setTenant_dn(Node.getDataWithDefault(XPath.getFirstMatch("*[local-name()='U_TENANTDN']", null, userXML), ""));
Tenant_Account.setTenant_code("99");
Tenant_Account.setOrg_id(8);
Tenant_Account.setIs_default((short)0);
Tenant_Account.setStatus_sign((short)1);
try
{
Tenant_Account.insert();
BSF.commitTransaction();
} catch (Exception e) {
e.printStackTrace();
BSF.abortTransaction();
return;
}finally
{
if (userXML != 0)
{
Node.delete(userXML);
userXML = 0;
}
}
}
}