Example usage for org.dom4j Document getRootElement

List of usage examples for org.dom4j Document getRootElement

Introduction

In this page you can find the example usage for org.dom4j Document getRootElement.

Prototype

Element getRootElement();

Source Link

Document

Returns the root Element for this document.

Usage

From source file:com.beetle.framework.persistence.access.DBConfig.java

License:Apache License

public static List<String> getAllDatasourcename() {
    Document doc = null;
    try {//from w w w . j a v a2  s  .c o  m
        List<String> myList = new ArrayList<String>();
        doc = XMLReader.getXmlDoc(AppProperties.getAppHome() + "DBConfig.xml");
        Element root = doc.getRootElement();
        for (Iterator<?> i = root.elementIterator("DataSources"); i.hasNext();) {
            Element e = (Element) i.next();
            @SuppressWarnings("unchecked")
            Iterator<Node> n = e.nodeIterator();
            while (n.hasNext()) {
                Node at = n.next();
                if (at.getName() != null) {
                    myList.add(at.getName());
                }
            }
        }
        return myList;
    } catch (Exception e) {
        throw new AppRuntimeException(e);
    } finally {
        if (doc != null) {
            doc.clearContent();
        }
    }
}

From source file:com.beyondb.geocoding.BaiduAPI.java

public static String getPointByAddress(String address, String city) throws IOException {
    String resultPoint = "";
    try {/*www.  j  ava2s. co m*/
        URL url = new URL("http://api.map.baidu.com/geocoder/v2/?ak=" + ak + "&output=xml&address=" + address
                + "&" + city);

        URLConnection connection = url.openConnection();
        /**
         * ??URLConnection?Web
         * URLConnection???Web???
         */
        connection.setDoOutput(true);
        OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "utf-8");
        //        remember to clean up
        out.flush();
        out.close();
        //        ?????

        String res;
        InputStream l_urlStream;
        l_urlStream = connection.getInputStream();
        if (l_urlStream != null) {
            BufferedReader in = new BufferedReader(new InputStreamReader(l_urlStream, "UTF-8"));
            StringBuilder sb = new StringBuilder("");
            while ((res = in.readLine()) != null) {
                sb.append(res.trim());
            }
            String str = sb.toString();
            System.out.println(str);
            Document doc = DocumentHelper.parseText(str); // XML
            Element rootElt = doc.getRootElement(); // ?
            //            System.out.println("" + rootElt.getName()); // ??
            Element resultElem = rootElt.element("result");
            if (resultElem.hasContent()) {
                Element locationElem = resultElem.element("location");
                Element latElem = locationElem.element("lat");
                //            System.out.print("lat:"+latElem.getTextTrim()+",");
                Element lngElem = locationElem.element("lng");
                //            System.out.println("lng:"+lngElem.getTextTrim());
                resultPoint = lngElem.getTextTrim() + "," + latElem.getTextTrim();
            } else {
                System.out.println("can't compute the coor");
                resultPoint = " , ";
            }
        } else {
            resultPoint = " , ";
        }

    } catch (DocumentException ex) {
        Logger.getLogger(BaiduAPI.class.getName()).log(Level.SEVERE, null, ex);
    }
    return resultPoint;
}

From source file:com.beyondb.geocoding.SkyMapAPI.java

/**
* ??????//from www .  jav  a 2 s  .c  om
*???????
* @param address
* @param city
* @return
*/
public Map<String, Coordinate> getPlaces(String address, String city) {
    Map<String, Coordinate> map = null;
    try {

        URL url = new URL(requestURL);//webService?XML?
        String soapRequest = getRequestXML(
                city == null || city.isEmpty() ? ("" + address) : (city + " " + address));

        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows XP; DigExt)");
        con.setRequestProperty("Content-Length", String.valueOf(soapRequest.length()));
        con.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
        // con.setRequestProperty("SOAPAction",_soap_action_str);

        con.setDoOutput(true);
        con.setConnectTimeout(3000);//3?,??ip???socket??????

        con.setRequestMethod("POST");
        con.setUseCaches(false);//post?

        OutputStream out = con.getOutputStream();

        out.write(soapRequest.getBytes());
        out.flush();
        out.close();
        int code = 0;

        StringBuilder content = new StringBuilder();
        code = con.getResponseCode(); //?????
        BufferedReader br;
        String line = "";
        if (code == HttpURLConnection.HTTP_OK) {

            br = new BufferedReader(new InputStreamReader(con.getInputStream()));

            while ((line = br.readLine()) != null) {
                content.append(line);

            }
            //? XML??
            //            <?xml version="1.0" encoding="UTF-8"?><wfs:FeatureCollection xmlns:topp="http://www.openplans.org/topp" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd" service="WFS" outputFormat="gml" version="1.0">
            //<gml:featureMember xmlns:iso19112="SI_Gazetteer"><iso19112:SI_Gazetteer><Geometry><gml:Point srsName="-1"><gml:coordinates>116.394272,39.900472</gml:coordinates></gml:Point></Geometry><ogc:id>1003716709</ogc:id><ogc:name></ogc:name><ogc:tel>010-65243322</ogc:tel><ogc:addnamel>44?</ogc:addnamel><ogc:admin>156110101</ogc:admin><ogc:cls>100102 100100 100000</ogc:cls><ogc:level/><ogc:zip/></iso19112:SI_Gazetteer></gml:featureMember>
            //<gml:featureMember xmlns:iso19112="SI_Gazetteer"><iso19112:SI_Gazetteer><Geometry><gml:Point srsName="-1"><gml:coordinates>116.394504,39.9013</gml:coordinates></gml:Point></Geometry><ogc:id>1003546134</ogc:id><ogc:name></ogc:name><ogc:tel>010-65241304</ogc:tel><ogc:addnamel>37?</ogc:addnamel><ogc:admin>156110101</ogc:admin><ogc:cls>100501 100500 100000 100105 100100 100000</ogc:cls><ogc:level/><ogc:zip/></iso19112:SI_Gazetteer></gml:featureMember>
            //<gml:featureMember xmlns:iso19112="SI_Gazetteer"><iso19112:SI_Gazetteer><Geometry><gml:Point srsName="-1"><gml:coordinates>116.393824,39.900068</gml:coordinates></gml:Point></Geometry><ogc:id>1025053239</ogc:id><ogc:name>?</ogc:name><ogc:tel>010-65122265</ogc:tel><ogc:addnamel>44?</ogc:addnamel><ogc:admin>156110101</ogc:admin><ogc:cls>010100 010000</ogc:cls><ogc:level/><ogc:zip/></iso19112:SI_Gazetteer></gml:featureMember>
            //<gml:featureMember xmlns:iso19112="SI_Gazetteer"><iso19112:SI_Gazetteer><Geometry><gml:Point srsName="-1"><gml:coordinates>116.3938,39.899528</gml:coordinates></gml:Point></Geometry><ogc:id>1003552834</ogc:id><ogc:name>?</ogc:name><ogc:tel>010-65241042</ogc:tel><ogc:addnamel>44?</ogc:addnamel><ogc:admin>156110101</ogc:admin><ogc:cls>010116 010100 010000</ogc:cls><ogc:level/><ogc:zip/></iso19112:SI_Gazetteer></gml:featureMember>
            //   <gml:featureMember xmlns:iso19112="SI_Gazetteer">
            //            <iso19112:SI_Gazetteer>
            //               <Geometry>
            //                  <gml:Point srsName="-1">
            //                     <gml:coordinates>116.3938,39.899532</gml:coordinates>
            //                  </gml:Point>
            //               </Geometry>
            //               <ogc:id>1021636362</ogc:id>
            //               <ogc:name>?</ogc:name>
            //               <ogc:tel>010-65241042</ogc:tel>
            //               <ogc:addnamel>44?</ogc:addnamel>
            //               <ogc:admin>156110101</ogc:admin>
            //               <ogc:cls>010116 010100 010000</ogc:cls>
            //               <ogc:level/>
            //               <ogc:zip/>
            //            </iso19112:SI_Gazetteer>
            //   </gml:featureMember>
            //</wfs:FeatureCollection>
            Document doc = DocumentHelper.parseText(content.toString()); // XML
            Element rootElt = doc.getRootElement(); // ?FeatureCollection

            for (Iterator it = rootElt.elementIterator("featureMember"); it.hasNext();) {
                if (map == null) {
                    map = new HashMap<>();
                }
                Element featureMemberElement = (Element) it.next();
                Element gazetterEle = featureMemberElement.element("SI_Gazetteer");
                Element geoEle = gazetterEle.element("Geometry");
                Element pointEle = geoEle.element("Point");
                Element coordEle = pointEle.element("coordinates");
                String[] coordinate = coordEle.getTextTrim().split(",");
                Coordinate tmpCoordinate = new Coordinate();
                tmpCoordinate.Longitude = Double.parseDouble(coordinate[0]);
                tmpCoordinate.Latitude = Double.parseDouble(coordinate[1]);
                Element nameEle = gazetterEle.element("name");
                map.put(nameEle.getTextTrim(), tmpCoordinate);
            }

        } else {
            //?HTTP??HTTP_OK??
            InputStream is = con.getErrorStream(); //getErrorStreamXML??JDOM??
            InputStreamReader isr = new InputStreamReader(is, "utf-8");
            br = new BufferedReader(isr);
            while ((line = br.readLine()) != null) {
                content.append(line);
            }
            Logger.getLogger(SkyMapAPI.class.getName()).log(Level.SEVERE, "??");
        }

    } catch (MalformedURLException e) {
        Logger.getLogger(SkyMapAPI.class.getName()).log(Level.SEVERE, null, e);
    } catch (IOException | DocumentException e) {
        Logger.getLogger(SkyMapAPI.class.getName()).log(Level.SEVERE, null, e);
    }
    return map;
}

From source file:com.beyondb.io.DBConfig.java

/**
 *??/*from   w w w  .  j  av a 2s . co m*/
 * @param path
 * @return
 */
public static DataSource readDBConfig(String path) {
    DataSource ds = null;

    try {

        SAXReader reader = new SAXReader();
        File file = new File(path);

        if (file.exists()) {
            Document doc = reader.read(file);

            Element datasource = doc.getRootElement();
            Element dbElement = datasource.element(Node_database);
            if (dbElement != null) {
                String id = dbElement.attribute(Attribute_id).getValue();
                String username = dbElement.attribute(Attribute_username).getValue();
                String password = dbElement.attribute(Attribute_password).getValue();
                String virtualNode = dbElement.attribute(Attribute_virtualNode).getValue();
                String url = dbElement.elementText(Attribute_jdbcurl);
                ds = new BydDataSource(url, username, password);
                ds.setVirtualNode(virtualNode);
                ds.setID(id);
            }

        }

    } catch (DocumentException ex) {

        Logger.getLogger(DBConfig.class.getName()).log(Level.SEVERE, "???", ex);
    }
    return ds;
}

From source file:com.beyondb.io.DBConfig.java

/**
 *??//from w w w  .j  a  va  2  s  .  c o  m
 * @param path
 * @return
 */
public static ArrayList<DataSource> readDBConfig1(String path) {
    ArrayList<DataSource> dslist = new ArrayList<>();

    try {

        SAXReader reader = new SAXReader();
        File file = new File(path);

        if (file.exists()) {
            Document doc = reader.read(file);

            Element datasource = doc.getRootElement();
            Iterator it = datasource.elementIterator(Node_database);
            while (it.hasNext()) {
                Element dbElement = (Element) it.next();
                String id = dbElement.attribute(Attribute_id).getValue();
                String username = dbElement.attribute(Attribute_username).getValue();
                String password = dbElement.attribute(Attribute_password).getValue();
                String virtualNode = dbElement.attribute(Attribute_virtualNode).getValue();
                String url = dbElement.elementText(Attribute_jdbcurl);

                DataSource ds = new BydDataSource(url, username, password);
                ds.setVirtualNode(virtualNode);
                ds.setID(id);
                dslist.add(ds);
            }

        }

    } catch (DocumentException ex) {

        Logger.getLogger(DBConfig.class.getName()).log(Level.SEVERE, "???", ex);
    }
    return dslist;
}

From source file:com.bizideal.whoami.utils.cloopen.CCPRestSmsSDK.java

License:Open Source License

/**
 * @description xml??map/*from   w  w  w .  ja  v  a2 s.c  o m*/
 * @param xml
 * @return Map
 */
private HashMap<String, Object> xmlToMap(String xml) {
    HashMap<String, Object> map = new HashMap<String, Object>();
    Document doc = null;
    try {
        doc = DocumentHelper.parseText(xml); // XML
        Element rootElt = doc.getRootElement(); // ?
        HashMap<String, Object> hashMap2 = new HashMap<String, Object>();
        for (Iterator i = rootElt.elementIterator(); i.hasNext();) {
            Element e = (Element) i.next();
            if ("statusCode".equals(e.getName()) || "statusMsg".equals(e.getName()))
                map.put(e.getName(), e.getText());
            else {
                if ("SubAccount".equals(e.getName()) || "totalCount".equals(e.getName())
                        || "token".equals(e.getName()) || "downUrl".equals(e.getName())) {
                    if (!"SubAccount".equals(e.getName())) {
                        hashMap2.put(e.getName(), e.getText());
                    } else {
                        ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String, Object>>();
                        HashMap<String, Object> hashMap3 = new HashMap<String, Object>();
                        for (Iterator i2 = e.elementIterator(); i2.hasNext();) {
                            Element e2 = (Element) i2.next();
                            hashMap3.put(e2.getName(), e2.getText());
                            arrayList.add(hashMap3);
                        }
                        hashMap2.put("SubAccount", arrayList);
                    }
                    map.put("data", hashMap2);
                } else {

                    HashMap<String, Object> hashMap3 = new HashMap<String, Object>();
                    for (Iterator i2 = e.elementIterator(); i2.hasNext();) {
                        Element e2 = (Element) i2.next();
                        // hashMap2.put(e2.getName(),e2.getText());
                        hashMap3.put(e2.getName(), e2.getText());
                    }
                    if (hashMap3.size() != 0) {
                        hashMap2.put(e.getName(), hashMap3);
                    } else {
                        hashMap2.put(e.getName(), e.getText());
                    }
                    map.put("data", hashMap2);
                }
            }
        }
    } catch (DocumentException e) {
        e.printStackTrace();
        LoggerUtil.error(e.getMessage());
    } catch (Exception e) {
        LoggerUtil.error(e.getMessage());
        e.printStackTrace();
    }
    return map;
}

From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java

License:Open Source License

public static void main(String[] args) {
    try {/*from w ww .j  a va2s .  c o m*/

        Document document = XMLDom4jUtils.createDocument();
        Element root = document.getRootElement();

        String test02 = "?";
        String test2 = "PHS(??)";

        Document doc = XMLDom4jUtils.createDocument();
        root = doc.addElement("address");
        for (int i = 0; i < 1; i++) {
            XMLDom4jUtils.appendChild(root, "name", test02);
            XMLDom4jUtils.appendChild(root, "city", "nj");
        }
        XMLDom4jUtils.appendChild(root, "state", test2);
        XMLDom4jUtils.appendChild(root, "sysDate", new Date());
        XMLDom4jUtils.appendChild(root, "intValue", 100);
        XMLDom4jUtils.toXML(doc, System.out, "utf-8");

        System.out.println("-------------------");
        //         XMLDom4jUtils.element2XML(root, System.out, "utf-8");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.bluexml.side.framework.alfresco.sharePortalExtension.PresetsManagerExtension.java

License:Open Source License

/**
 * Construct the model objects for a given preset.
 * Objects persist to the default store for the appropriate object type.
 * /*from   w  ww  .j  a  va  2 s .c o m*/
 * @param id
 *            Preset ID to use
 * @param tokens
 *            Name value pair tokens to replace in preset definition
 */
public void constructPreset(String id, Map<String, String> tokens) {
    if (id == null) {
        throw new IllegalArgumentException("Preset ID is mandatory.");
    }

    // perform one time init - this cannot be perform in an app handler or by the
    // framework init - as it requires the Alfresco server to be started...
    synchronized (this) {
        if (this.documents == null) {
            init();
        }
    }

    for (Document doc : this.documents) {
        for (Element preset : (List<Element>) doc.getRootElement().elements("preset")) {
            // found preset with matching id?
            if (id.equals(preset.attributeValue("id"))) {
                // any components in the preset?
                Element components = preset.element("components");
                if (components != null) {
                    for (Element c : (List<Element>) components.elements("component")) {
                        // apply token replacement to each value as it is retrieved
                        String title = replace(c.elementTextTrim(Component.PROP_TITLE), tokens);
                        String titleId = replace(c.elementTextTrim(Component.PROP_TITLE_ID), tokens);
                        String description = replace(c.elementTextTrim(Component.PROP_DESCRIPTION), tokens);
                        String descriptionId = replace(c.elementTextTrim(Component.PROP_DESCRIPTION_ID),
                                tokens);
                        String typeId = replace(c.elementTextTrim(Component.PROP_COMPONENT_TYPE_ID), tokens);
                        String scope = replace(c.elementTextTrim(Component.PROP_SCOPE), tokens);
                        String regionId = replace(c.elementTextTrim(Component.PROP_REGION_ID), tokens);
                        String sourceId = replace(c.elementTextTrim(Component.PROP_SOURCE_ID), tokens);
                        String url = replace(c.elementTextTrim(Component.PROP_URL), tokens);
                        String chrome = replace(c.elementTextTrim(Component.PROP_CHROME), tokens);

                        // validate mandatory values
                        if (scope == null || scope.length() == 0) {
                            throw new IllegalArgumentException(
                                    "Scope is a mandatory property for a component preset.");
                        }
                        if (regionId == null || regionId.length() == 0) {
                            throw new IllegalArgumentException(
                                    "RegionID is a mandatory property for a component preset.");
                        }
                        if (sourceId == null || sourceId.length() == 0) {
                            throw new IllegalArgumentException(
                                    "SourceID is a mandatory property for a component preset.");
                        }

                        // generate component
                        Component component = modelObjectService.newComponent(scope, regionId, sourceId);
                        component.setComponentTypeId(typeId);
                        component.setTitle(title);
                        component.setTitleId(titleId);
                        component.setDescription(description);
                        component.setDescriptionId(descriptionId);
                        component.setURL(url);
                        component.setChrome(chrome);

                        // apply arbituary custom properties
                        if (c.element("properties") != null) {
                            for (Element prop : (List<Element>) c.element("properties").elements()) {
                                String propName = replace(prop.getName(), tokens);
                                String propValue = replace(prop.getTextTrim(), tokens);
                                component.setCustomProperty(propName, propValue);
                            }
                        }

                        // persist the object
                        modelObjectService.saveObject(component);
                    }
                }

                // any pages in the preset?
                Element pages = preset.element("pages");
                if (pages != null) {
                    for (Element p : (List<Element>) pages.elements("page")) {
                        // apply token replacement to each value as it is retrieved
                        String pageId = replace(p.attributeValue(Page.PROP_ID), tokens);
                        String title = replace(p.elementTextTrim(Page.PROP_TITLE), tokens);
                        String titleId = replace(p.elementTextTrim(Page.PROP_TITLE_ID), tokens);
                        String description = replace(p.elementTextTrim(Page.PROP_DESCRIPTION), tokens);
                        String descriptionId = replace(p.elementTextTrim(Page.PROP_DESCRIPTION_ID), tokens);
                        String typeId = replace(p.elementTextTrim(Page.PROP_PAGE_TYPE_ID), tokens);
                        String auth = replace(p.elementTextTrim(Page.PROP_AUTHENTICATION), tokens);
                        String template = replace(p.elementTextTrim(Page.PROP_TEMPLATE_INSTANCE), tokens);

                        // validate mandatory values
                        if (pageId == null || pageId.length() == 0) {
                            throw new IllegalArgumentException(
                                    "ID is a mandatory attribute for a page preset.");
                        }
                        if (template == null || template.length() == 0) {
                            throw new IllegalArgumentException(
                                    "Template is a mandatory property for a page preset.");
                        }

                        // generate page
                        Page page = modelObjectService.newPage(pageId);
                        page.setPageTypeId(typeId);
                        page.setTitle(title);
                        page.setTitleId(titleId);
                        page.setDescription(description);
                        page.setDescriptionId(descriptionId);
                        page.setAuthentication(auth);
                        page.setTemplateId(template);

                        // apply arbituary custom properties
                        if (p.element("properties") != null) {
                            for (Element prop : (List<Element>) p.element("properties").elements()) {
                                String propName = replace(prop.getName(), tokens);
                                String propValue = replace(prop.getTextTrim(), tokens);
                                page.setCustomProperty(propName, propValue);
                            }
                        }

                        // persist the object
                        modelObjectService.saveObject(page);
                    }
                }

                // any template instances in the preset?
                Element templates = preset.element("template-instances");
                if (templates != null) {
                    for (Element t : (List<Element>) templates.elements("template-instance")) {
                        // apply token replacement to each value as it is retrieved
                        String templateId = replace(t.attributeValue(TemplateInstance.PROP_ID), tokens);
                        String title = replace(t.elementTextTrim(TemplateInstance.PROP_TITLE), tokens);
                        String titleId = replace(t.elementTextTrim(TemplateInstance.PROP_TITLE_ID), tokens);
                        String description = replace(t.elementTextTrim(TemplateInstance.PROP_DESCRIPTION),
                                tokens);
                        String descriptionId = replace(t.elementTextTrim(TemplateInstance.PROP_DESCRIPTION_ID),
                                tokens);
                        String templateType = replace(t.elementTextTrim(TemplateInstance.PROP_TEMPLATE_TYPE),
                                tokens);

                        // validate mandatory values
                        if (templateId == null || templateId.length() == 0) {
                            throw new IllegalArgumentException(
                                    "ID is a mandatory attribute for a template-instance preset.");
                        }
                        if (templateType == null || templateType.length() == 0) {
                            throw new IllegalArgumentException(
                                    "Template is a mandatory property for a page preset.");
                        }

                        // generate template-instance
                        TemplateInstance template = modelObjectService.newTemplate(templateId);
                        template.setTitle(title);
                        template.setTitleId(titleId);
                        template.setDescription(description);
                        template.setDescriptionId(descriptionId);
                        template.setTemplateTypeId(templateType);

                        // apply arbituary custom properties
                        if (t.element("properties") != null) {
                            for (Element prop : (List<Element>) t.element("properties").elements()) {
                                String propName = replace(prop.getName(), tokens);
                                String propValue = replace(prop.getTextTrim(), tokens);
                                template.setCustomProperty(propName, propValue);
                            }
                        }

                        // persist the object
                        modelObjectService.saveObject(template);
                    }
                }

                // TODO: any chrome, associations, types, themes etc. in the preset...

                // found our preset - no need to process further
                break;
            }
        }
    }
}

From source file:com.bluexml.side.framework.alfresco.sharePortalExtension.PresetsManagerExtension.java

License:Open Source License

public List<String> getPresetsIds() {
    List<String> ids = new ArrayList<String>();
    synchronized (this) {
        if (this.documents == null) {
            init();//www.  ja  va 2  s . co m
        }
    }
    for (Document doc : this.documents) {
        for (Element preset : (List<Element>) doc.getRootElement().elements("preset")) {
            // found preset with matching id?
            ids.add(preset.attributeValue("id"));
        }
    }
    return ids;
}

From source file:com.brick.util.nciic.NciicUtil.java

/**
 * ?XML//w  w  w .  j  av  a 2s .c  o  m
 * @param text
 * @return
 * @throws Exception
 */
public static List<NciicEntity> readResult(String text) throws Exception {
    List<NciicEntity> resultList = new ArrayList<NciicEntity>();
    NciicEntity result = null;
    Document d;
    XMLWriter writer = null;
    try {
        //SAXReader reader = new SAXReader();
        //d = reader.read(new File("d:/test/testxml.xml"));
        d = DocumentHelper.parseText(text);
        String dateStr = DateUtil.dateToString(new Date(), "[yyyy-MM-dd][HH-mm]");
        File xmlPath = new File(XML_PATH);
        if (!xmlPath.exists()) {
            xmlPath.mkdirs();
        }
        File xpPath = new File(XP_PATH);
        if (!xpPath.exists()) {
            xpPath.mkdirs();
        }
        writer = new XMLWriter(new FileOutputStream(new File(xmlPath, dateStr + ".xml")));
        writer.write(d);
        writer.flush();
        writer.close();
        writer = null;

        Element root = d.getRootElement();
        List<Element> allResult = root.elements("ROW");
        Element input = null;
        List<Element> output = null;
        String result_msg = null;
        for (Element element : allResult) {
            result = new NciicEntity();
            result_msg = null;
            input = element.element("INPUT");
            result.setGmsfhm(input.element("gmsfhm").getText());
            result.setXm(input.element("xm").getText());
            output = element.element("OUTPUT").elements("ITEM");
            for (Element out_element : output) {
                if (out_element.element("result_gmsfhm") != null) {
                    result.setResult_gmsfhm(out_element.element("result_gmsfhm").getText());
                }
                if (out_element.element("result_xm") != null) {
                    result.setResult_xm(out_element.element("result_xm").getText());
                }
                if (out_element.element("errormesage") != null) {
                    result.setError_msg(out_element.element("errormesage").getText());
                }
                if (out_element.element("errormesagecol") != null) {
                    result.setError_msg_col(out_element.element("errormesagecol").getText());
                }
                if (out_element.element("xp") != null) {
                    result.setXp(out_element.element("xp").getText());
                }
                if (!StringUtils.isEmpty(result.getXp())) {
                    try {
                        File f = new File(xpPath, result.getGmsfhm() + "-" + result.getXm() + ".jpg");
                        BufferedImage img = ImageIO.read(
                                new ByteArrayInputStream(new BASE64Decoder().decodeBuffer(result.getXp())));
                        ImageIO.write(img, "jpg", f);
                        result.setXp_file(f.getPath());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            if ("".equals(result.getResult_gmsfhm()) && "".equals(result.getResult_xm())) {
                result_msg = "";
            } else {
                if ("?".equals(result.getResult_gmsfhm())) {
                    result_msg = "???";
                } else if ("?".equals(result.getResult_xm())) {
                    result_msg = "???";
                } else if (!StringUtils.isEmpty(result.getError_msg())) {
                    result_msg = result.getError_msg();
                    if (!StringUtils.isEmpty(result.getError_msg_col())) {
                        result_msg += "(" + result.getError_msg_col() + ")";
                    }
                }
            }
            result.setResult_msg(result_msg);
            resultList.add(result);
        }
        return resultList;
    } catch (Exception e) {
        throw e;
    } finally {
        if (writer != null) {
            writer.flush();
            writer.close();
            writer = null;
        }
    }
}