JAXB如何使用标记中的冒号(:)处理属性? - > CIM:ACLineSegment

时间:2017-04-10 11:20:54

标签: java jaxb unmarshalling

我正在尝试使用JAXB解组CIM文件。当任何标记包含:(冒号)时,结果始终为null。如果我删除冒号,那么它运作良好。 我文件中的标签示例: 谢谢。

 <cim:ACLineSegment>
        <cim:ACLineSegment.r>2.200000</cim:ACLineSegment.r>
        <cim:ACLineSegment.x>68.200000</cim:ACLineSegment.x>
        <cim:ACLineSegment.bch>0.0000829380</cim:ACLineSegment.bch>
</cim:ACLineSegment>

这里的Java代码:

    package JAXB_read;
    import javax.xml.bind.annotation.*;

    @XmlRootElement(name="cimACLineSegment")
    @XmlAccessorType(XmlAccessType.FIELD)

    public class AClineSegment {

        @XmlElement(name ="cimACLineSegment.r")
        private double resistance;

        @XmlElement(name ="cimACLineSegment.x")
        private double reactance;

        @XmlElement(name ="cimACLineSegment.bch")
        private double susceptance;


        public double getResistance() {
            return resistance;
        }
        public void setResistance(double resistance) {
            this.resistance = resistance;
        }

        public double getReactance() {
            return reactance;
        }
        public void setReactance(double reactance) {
            this.reactance = reactance;
        }

        public double getSusceptance() {
            return susceptance;
        }
        public void setSusceptance(double susceptance) {
            this.susceptance = susceptance;
        }
        public AClineSegment(double resistance, double reactance, double susceptance) {
            super();
            this.resistance = resistance;
            this.reactance = reactance;
            this.susceptance = susceptance;
        }
        public AClineSegment() {
            super();
        }


    }

    package JAXB_read;

import java.io.File;

import javax.xml.bind.*;



    public class AClineSegementJAXB {
        public void unmarshall()
        {
            try {
                JAXBContext jc = JAXBContext.newInstance(AClineSegment.class);
                Unmarshaller ums = jc.createUnmarshaller();
                AClineSegment ACline = (AClineSegment)ums.unmarshal(new File("src\\data\\AclineSegment.txt"));
                System.out.println("Informations:");
                System.out.println("----------------------");
                System.out.println("Resistance: "+ACline.getResistance());
                System.out.println("Reactance: "+ACline.getReactance());
                System.out.println("Susceptance: "+ACline.getSusceptance());

            } catch (Exception e) {
                System.out.println(""+e.getMessage());
            }

    }
    }


    package Main;

    import JAXB_read.*;
    import javax.xml.bind.annotation.XmlAttribute;
    import javax.xml.bind.annotation.XmlRootElement;
    // AC LINE SSEGMENT 
    public class Main {

        public static void main(String[] args)
        {
            AClineSegementJAXB object = new AClineSegementJAXB();
            object.unmarshall();

        }

    }

0 个答案:

没有答案