首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

XML跟String数据替换 DataCache 03

2012-09-10 
XML和String数据替换 DataCache 03private static void initalEsbmDBfield(String path){// 初始化XML的解

XML和String数据替换 DataCache 03
    private static void initalEsbmDBfield(String path)
    {
        // 初始化XML的解析器
        DocumentBuilderFactory documentFactory = DocumentBuilderFactory
                .newInstance();
        DocumentBuilder documentBuilder = null;
        Document doc = null;
        try
        {
            documentBuilder = documentFactory.newDocumentBuilder();
            doc = (Document) documentBuilder.parse(path);
            // 得到tablelist的子节点有三个<esbtable>
            NodeList node_i = doc.getDocumentElement().getChildNodes();
            Node node = null;
            Node fieldNode = null;
            String tablename = null;
            List<EsbTableField> listField = null;
            for (int i = 0; i < node_i.getLength(); i++)
            {
                // 取到esbtable节点,这是多节点
                node = (Node) node_i.item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE)
                {
                    // 取到esbtable节点数据得到表名
                    tablename = node.getAttributes().getNamedItem("tablename")
                            .getNodeValue();
                    // 取到fieldlist节点
                    fieldNode = node.getChildNodes().item(0);
                    // 取到fieldlist中的field加点内容,将field转换成List<EsbTableField>
                    listField = getEsbmTableField(fieldNode);
                    logger.debug("Esb table name = " + tablename
                            + " field size = " + listField.size());

                    esbmTable.put(tablename, listField);
                }
            }
        }
        catch (Exception e)
        {
            logger.error("Parse Document fail", e);
        }
    }

    public static List<EsbTableField> getEsbmTableField(Node node)
    {
        List<EsbTableField> list = new ArrayList<EsbTableField>();
        try
        {
            // fieldList Node
            NodeList nodeList = node.getChildNodes();
            Node fieldNode = null;
            EsbTableField esbTableField = null;
            // 遍历fieldlist中的field节点
            for (int i = 0; i < nodeList.getLength(); i++)
            {
                fieldNode = nodeList.item(i);
                if (fieldNode.getNodeType() == Node.ELEMENT_NODE)
                {
                    esbTableField = getEsbTableField((Element) fieldNode);
                    list.add(esbTableField);
                }
            }
        }
        catch (Exception e)
        {
            logger.error("getEsbmTableField has error:" + e.getMessage());
        }
        return list;
    }
   
    public static EsbTableField getEsbTableField(Element empEl)
    {
     // 获取<field> 中的<fieldname>节点值
        String fieldname = getTextValue(empEl, "fieldname");
        // 获取<field> 中的<xpathfield>节点值
        String xpathField = getTextValue(empEl, "xpathfield");
        // 获取<field> 中的<datetype>节点值
        String datetype = getTextValue(empEl, "datetype");
       
        EsbTableField esbTableField = new EsbTableField(fieldname, xpathField,
                datetype);
        return esbTableField;
    }
   
    public static String getTextValue(Element el,String tagName)
    {
        String textVal=null;
        NodeList nl=el.getElementsByTagName(tagName);
        if(nl!=null && nl.getLength()>0)
        {
            Element ele=(Element) nl.item(0);
            textVal=ele.getFirstChild().getNodeValue();
        }
        return textVal;
    }
   
    public static Map<Object, Object> getinterfaceMap(String intefaceName)
    {

        return allProperties.get(intefaceName);
    }

}

热点排行