1
我正在使用Java,我需要從一個AutomationML文件(XML類型文件)中獲取信息。我嘗試使用JAXB來做到這一點,但最終我無法獲得所需的信息。 在AML中,我有一個具有3個InternalElements的InstanceHierarchy,並且有一些屬性,我需要這個屬性值,但是使用JAXB我得到了AttributeName,但我無法獲得它的值。解析XML類型文件
public static void main(String[] args) throws Exception {
CAEXFile caex = null;
CAEXFile.InstanceHierarchy ih = null;
try {
JAXBContext jc = JAXBContext.newInstance(CAEXFile.class);
//JAXBContext jc = JAXBContext.newInstance(generated.CAEXFile.InstanceHierarchy.class);
Unmarshaller ums = jc.createUnmarshaller();
CAEXFile aml = (CAEXFile)ums.unmarshal(new File("src\\teste2.aml"));
System.out.println("ins = " + aml.getInstanceHierarchy().get(0).getInternalElement().get(0).getAttribute().get(0).getName());
} catch (JAXBException e) {
System.out.println(e.getMessage());
}
}
XSD文件XSD (CAEX)和AML文件AML 有人可以幫助我使用JAXB或者給我一些方向如何解決這個問題? 在此先感謝。
感謝您的答覆,我帶雙解組解決;) –