<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 閱讀(422) 評論(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() + "\"");
            }

        }

    }

    主站蜘蛛池模板: 亚洲一级毛片免费看| 免费无遮挡无码视频在线观看| 男女超爽刺激视频免费播放| 亚洲愉拍一区二区三区| 亚洲精品国产va在线观看蜜芽| 免费视频一区二区| 亚洲国产精品成人AV在线| AV在线播放日韩亚洲欧| 97性无码区免费| 国产日韩AV免费无码一区二区三区| 亚洲精品国产啊女成拍色拍| 国产免费av一区二区三区| 99re这里有免费视频精品| 亚洲AV网一区二区三区| 久久久久久亚洲av成人无码国产| 色吊丝永久在线观看最新免费| 女人隐私秘视频黄www免费| 亚洲熟妇成人精品一区| 久久精品国产亚洲av麻| 永久免费毛片手机版在线看| 久久亚洲免费视频| 国产亚洲福利一区二区免费看| 亚洲综合色一区二区三区小说| 亚洲性在线看高清h片| 四虎永久在线精品免费网址 | 亚洲狠狠婷婷综合久久久久| 成年男女男精品免费视频网站| 国产精品免费AV片在线观看| 国产成人高清亚洲一区91| 亚洲国产av高清无码| 亚洲AV永久精品爱情岛论坛| 亚洲阿v天堂在线2017免费| 成人免费视频77777| 人妻无码一区二区三区免费| 精品无码一级毛片免费视频观看| 亚洲乱码无人区卡1卡2卡3| 亚洲成AV人片久久| 亚洲欧洲日韩不卡| 久久亚洲精品中文字幕三区| 亚洲一区精品伊人久久伊人| 国产午夜影视大全免费观看|