01. 制作一个XML文件, 然后导入到Component里的Resource>src>mimes>com.**.**.DataComp里面
02. DC里面只需要Component, 其余window,View, Interface views 等都删掉
03. DataCompInterfae 里面以XML的element为准命名Context
04. 用Data Link 链接到Component Controller data mapping
05. 声明一个继承DefaultHandler的class
//@@begin others private class EmployeeParsingHandler extends DefaultHandler{ } //@@end
06. 在此class中单击右键选择 Source-> Override/Implement Method
07. 在弹出框里选择characters, endElement, startElement
08. 填写代码如下
//@@begin others private class EmpsloyeeParsingHandler extends DefaultHandler{ StringBuilder tagContentBuilder = new StringBuilder(); IEmployeeElement currentElement = null; } //@@end
09. 一下代码同样是上述class当中的
characters calss
@Override public void characters(char[] ch,int start,int length) throws SAXException { // TODO Auto-generated method stub tagContentBuilder.append(ch,start,length); //super.characters(ch,length); }
endElement Class
@Override public void endElement(String uri,String localName,String qName) throws SAXException { // TODO Auto-generated method stub //super.endElement(uri,localName,qName); String value = tagContentBuilder.toString().trim(); if(currentElement != null){ if(qName.equalsIgnoreCase("employee")){ if("f".equals(currentElement.getSex())){ try{ currentElement.setPicture(WDURLGenerator.getAbsoluteWebResourceURL(wdThis.wdGetAPI().getDeployableObjectPart(),"female.png")); }catch(WDURLException e){ } }else{ try{ currentElement.setPicture(WDURLGenerator.getAbsoluteWebResourceURL(wdThis.wdGetAPI().getDeployableObjectPart(),"male.png")); } catch(WDURLException e){} } }else if(qName.equals("picture")){ if(value != null){ try{ value = WDURLGenerator.getAbsoluteWebResourceURL(wdThis.wdGetAPI().getDeployableObjectPart(),value); }catch(WDURLException e){} } currentElement.setPers_number(value); }else if(qName.equalsIgnoreCase("entry_date")){ if(value != null){ Date date = null; try{ DateFormat format = DateFormat.getDateInstance( DateFormat.MEDIUM,Locale.GERMAN); java.util.Date d = format.parse(value); date = new Date(d.getTime()); currentElement.setEntry_date(date); }catch(Exception e){} } }else if(qName.equalsIgnoreCase("salutation")){ currentElement.setSalutation(value); }else if(qName.equalsIgnoreCase("sex")){ currentElement.setSex(value); }else if(qName.equalsIgnoreCase("firstname")){ currentElement.setFirstname(value); }else if(qName.equalsIgnoreCase("lastname")){ currentElement.setLastname(value); }else if(qName.equalsIgnoreCase("business_address_phone")){ currentElement.currentBusinessAddressElement().setPhone(value); }else if(qName.equalsIgnoreCase("private_address_city")){ currentElement.currentPrivateAddressElement().setCity(value); }else if(qName.equalsIgnoreCase("private_address_postal_code")){ currentElement.currentPrivateAddressElement().setPostal_code(value); }else if(qName.equalsIgnoreCase("private_address_strees")){ currentElement.currentPrivateAddressElement().setStreet(value); }else if(qName.equalsIgnoreCase("private_address_building")){ currentElement.currentPrivateAddressElement().setBuilding(value); }else if(qName.equalsIgnoreCase("private_address_country")){ currentElement.currentPrivateAddressElement().setCountry(value); }else if(qName.equalsIgnoreCase("business_address_company")){ currentElement.currentBusinessAddressElement().setCompany(value); }else if(qName.equalsIgnoreCase("business_address_city")){ currentElement.currentBusinessAddressElement().setCity(value); }else if(qName.equalsIgnoreCase("business_address_state")){ currentElement.currentBusinessAddressElement().setState(value); }else if(qName.equalsIgnoreCase("business_address_street")){ currentElement.currentBusinessAddressElement().setStreet(value); }else if(qName.equalsIgnoreCase("business_address_postal_code")){ currentElement.currentBusinessAddressElement().setPostal_code(value); }else if(qName.equalsIgnoreCase("business_address_building")){ currentElement.currentBusinessAddressElement().setBuilding(value); }else if(qName.equalsIgnoreCase("business_address_room_number")){ currentElement.currentBusinessAddressElement().setRoom_number(value); }else if(qName.equalsIgnoreCase("business_address_country")){ currentElement.currentBusinessAddressElement().setCountry(value); }else if(qName.equalsIgnoreCase("department_id")){ currentElement.currentBusinessAddressElement().setDepartment_id(value); } } tagContentBuilder.setLength(0); }
StartElement Calss
@Override public void startElement(String uri,String qName,Attributes attributes) throws SAXException { // TODO Auto-generated method stub //super.startElement(uri,qName,attributes); if(qName.equalsIgnoreCase("employee")){ currentElement = wdContext.createAndAddEmployeeElement(); } }