<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    無線&移動互聯網技術研發

    換位思考·····
    posts - 19, comments - 53, trackbacks - 0, articles - 283
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    jdom 解析 xml (csdn)

    Posted on 2009-07-26 00:37 Gavin.lee 閱讀(429) 評論(0)  編輯  收藏 所屬分類: xml doc 操作

    jdom parse xml

    from:http://topic.csdn.net/t/20041231/11/3691173.html

    <?xml version="1.0" encoding="GB2312"?> 
    <specificationSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation
    ="http://www.citi.qut.edu.au/yawl YAWL_Schema.xsd" 
    xmlns
    ="http://www.citi.qut.edu.au/yawl" 
    xmlns:mm
    ="www.citi.qut.edu.au/yawl/exampleSchemas/make_trip"> 
    <specification uri="Maketrip1.ywl"> 
        
    <metaData/> 
        
    <decomposition id="pay" xsi:type="問題在這里!如何處理帶有命名空間的屬性?"> 
            
    <inputParam name="customer"> 
                
    <type>xs:string</type> 
            
    </inputParam> 

            
    <inputParam name="payment_account_number"> 
                
    <type>xs:string</type> 
            
    </inputParam> 

            
    <inputParam name="carDetails"> 
                
    <type>xs:string</type> 
            
    </inputParam> 

            
    <inputParam name="hotelDetails"> 
                
    <type>xs:string</type> 
            
    </inputParam> 

            
    <inputParam name="flightDetails"> 
                
    <type>xs:string</type> 
            
    </inputParam> 
        
    </decomposition> 
    </specification> 
    </specificationSet>

    package com.Gavin.tools.xml;

    import java.io.File;
    import java.util.List;

    import org.jdom.Attribute;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.Namespace;
    import org.jdom.input.SAXBuilder;

    public class JdomParse {
        
    private static StringBuffer strbuf = new StringBuffer();

        
    public static void main(String[] argv) {
            
    try {
                SAXBuilder sb 
    = new SAXBuilder();
                Document doc 
    = sb.build(new File("c:/jdom.xml"));
                Element root 
    = doc.getRootElement();
                strbuf.append(
    "<?xml   version=\"1.0\"   encoding=\"GB2312\"?>").append(System.getProperty("line.separator"));
                strbuf.append(
    "<").append(root.getName());
                
                
    if (!"".equals(root.getNamespaceURI())) {// Namespace信息
                    strbuf.append("   xmlns=\"" + root.getNamespaceURI() + "\"");
                }

                
                
    // 得到附加的Namespace,比如:xmlns:xsi
                accessAdditionalNamespaces(root);
                
    // 得到附加的Namespace的屬性,如:xsi:schemaLocation
                accessAttribute(root);
                
                strbuf.append(
    ">");
                
    // 遍歷節點!
                accessElement(root);
                strbuf.append(
    "</" + root.getName() + ">");
                
                System.out.println(strbuf.toString());
            }
     catch (Exception e) {
                e.printStackTrace();
            }

        }


        
    /**
         * accessElement 遍歷結點
         * 
         * 
    @param parent
         *            Element
         
    */

        
    public static void accessElement(Element parent) {
            List listChild 
    = parent.getChildren();
            
    int iChild = listChild.size();
            
    for (int i = 0; i < iChild; i++{
                Element e 
    = (Element) listChild.get(i);
                strbuf.append(System.getProperty(
    "line.separator"));
                strbuf.append(
    "     <");
                strbuf.append(e.getName());
                
    // 訪問屬性
                accessAttribute(e);
                strbuf.append(
    ">");
                strbuf.append(e.getTextTrim());
                
    // 遞歸訪問節點
                accessElement(e);
                strbuf.append(
    "</");
                strbuf.append(e.getName());
                strbuf.append(
    ">");
            }

            
    // 恰當換行成XML原有的格式
            if (iChild > 0{
                strbuf.append(System.getProperty(
    "line.separator"));
            }

        }


        
    /**
         * accessAttribute 訪問結點的屬性
         * 
         * 
    @param e
         *            Element
         
    */

        
    public static void accessAttribute(Element e) {
            List listAttributes 
    = e.getAttributes();
            
    int iAttributes = listAttributes.size();
            
    for (int j = 0; j < iAttributes; j++{
                Attribute attribute 
    = (Attribute) listAttributes.get(j);
                
    // 問題:屬性帶有命名空間xsi:的怎么處理?
                
    // <name xsi:type="Full">YuLimin</name>
                
    // + attribute.getNamespacePrefix() + ":"
                strbuf.append("   " + attribute.getName() + "=\""
                        + attribute.getValue() + "\"");
            }

        }


        
    /**
         * accessAdditionalNamespaces 訪問附加的命名空間
         * 
         * 
    @param e
         *            Element
         
    */

        
    public static void accessAdditionalNamespaces(Element e) {
            List listAdditionalNamespaces 
    = e.getAdditionalNamespaces();
            
    int iAttributes = listAdditionalNamespaces.size();
            
    for (int j = 0; j < iAttributes; j++{
                Namespace namespace 
    = (Namespace) listAdditionalNamespaces.get(j);
                strbuf.append(
    "   xmlns:" + namespace.getPrefix() + "=\""
                        + namespace.getURI() + "\"");
            }

        }

    }

    主站蜘蛛池模板: 亚洲蜜芽在线精品一区| 男女一边桶一边摸一边脱视频免费| 久久精品国产亚洲av麻豆图片| 永久免费A∨片在线观看| 久久精品亚洲男人的天堂| 亚洲国产片在线观看| 67194国产精品免费观看| 亚洲乱亚洲乱少妇无码| 四虎影视永久在线精品免费| 黄色网址免费观看| 久久精品国产亚洲AV忘忧草18| 日韩毛片免费无码无毒视频观看| 亚洲亚洲人成综合网络| 亚洲暴爽av人人爽日日碰| 麻花传媒剧在线mv免费观看| 亚洲宅男天堂a在线| 在线视频免费观看www动漫| 亚洲AV无码一区二区三区性色| aⅴ免费在线观看| 在线观看亚洲AV日韩AV| 又粗又大又猛又爽免费视频| 久久国产乱子伦精品免费午夜 | 亚洲国产精品嫩草影院在线观看 | 亚洲日本成本人观看| 亚洲精品视频久久久| 精品国产麻豆免费人成网站| 亚洲美免无码中文字幕在线| 好男人视频在线观看免费看片| 久久亚洲色WWW成人欧美| 亚洲精品无码久久久久| 久久国产免费福利永久| 久久久久亚洲AV无码去区首| 久久亚洲国产精品五月天婷| 91短视频在线免费观看| 成人婷婷网色偷偷亚洲男人的天堂| 成人免费午夜视频| 东方aⅴ免费观看久久av | 全部在线播放免费毛片| 波多野结衣一区二区免费视频| 国产午夜成人免费看片无遮挡| 亚洲六月丁香婷婷综合|