我为UML活动图生成了一个XML。我想为XML生成一个树形结构,以便找到可能的转换路径。尝试使用DOMXML java解析器,但没有结果。我需要将活动分组为节点,将过渡分组为边。还附加了XML文件。请提供帮助
<<p> Java代码/strong> public class DomXMLParser {
public static void main(String[] args) throws ParserConfigurationException, SAXException,
IOException, XPathExpressionException {
//DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
File fXmlFile = new File("C:/Projekte/activity.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
dbFactory.setNamespaceAware(true);
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
javax.xml.xpath.XPathExpression expr
= xpath.compile("//xmi:XMI[xmi:type ='uml:Activity']/name/text()");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
System.out.println(nodes.item(i).getNodeValue());
}
Eclipse Modeling Framework (EMF)设计来读取UML模型。我写了一个代码来读取UML类图阅读EMF。您在Enterprise Architect中设计您的模型,因此导出为UMl模型或在基于EMF的纸莎草纸中设计
<?xml version="1.0" encoding="windows-1252"?>
<xmi:XMI xmi:version="2.1" xmlns:uml="http://schema.omg.org/spec/UML/2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:StandardProfileL2="http://www.omg.org/spec/UML/20110701/StandardProfileL2.xmi">
<xmi:Documentation exporter="Enterprise Architect" exporterVersion="6.5"/>
<uml:Model xmi:type="uml:Model" name="EA_Model" visibility="public">
<packagedElement xmi:type="uml:Package"xmi:id="EAPK_263A2FE8_8346_4d1e_A851_39B9D573143D" name="Activity Model" visibility="public">
<ownedComment xmi:type="uml:Comment" xmi:id="EAID_DDCEE555_5FD6_487c_BB82_A5F055D67309" body="Case 3: Btn_Pressed = 3">
<annotatedElement xmi:idref="EAID_367AB5AB_2A9C_4387_B4A2_2974CE57D11E"/>
</ownedComment>
<packagedElement xmi:type="uml:Activity" xmi:id="EAID_A165F2B1_D71E_4c10_8EB4_745B37742C0F" name="Start CnrtLk_Main()" visibility="public" isReadOnly="false" isSingleExecution="false"/>
<edge xmi:type="uml:ControlFlow" xmi:id="EAID_5350396C_9C67_4190_817C_9EEF1E34582C" visibility="public" source="EAID_A165F2B1_D71E_4c10_8EB4_745B37742C0F" target="EAID_6428B619_8065_4a57_99CD_8F19CFB6F136"/>
<packagedElement xmi:type="uml:Activity" xmi:id="EAID_6428B619_8065_4a57_99CD_8F19CFB6F136" name="Get Parameters" visibility="public" isReadOnly="false" isSingleExecution="false"/>
<edge xmi:type="uml:ControlFlow" xmi:id="EAID_A0B50908_8ADF_4507_8033_E77D777E21DD" visibility="public" source="EAID_6428B619_8065_4a57_99CD_8F19CFB6F136" target="EAID_32296133_1810_41c5_9A4D_6D3B6F11FF52"/>
<node xmi:type="uml:InitialNode" xmi:id="EAID_CF9A7618_F1C4_4395_94D5_D2F483A51119" name="System_Initial" visibility="public">
<outgoing xmi:idref="EAID_2785D6B4_D4DF_442f_AF8B_657D85367743"/>
</node>
<node xmi:type="uml:ActivityFinalNode" xmi:id="EAID_D2EB427B_3AFD_4700_BD72_13B36684E595" name="ActivityFinal" visibility="public">
<incoming xmi:idref="EAID_E036A3F5_4C88_4471_9C2F_031554144E9E"/>
<incoming xmi:idref="EAID_D62F8934_F4E6_4b00_A35B_E1149E4C06E6"/>
<incoming xmi:idref="EAID_CC1E7F54_9C97_4aec_AE53_55AD4DA43408"/>
<incoming xmi:idref="EAID_ADD5D207_728A_4aeb_80EB_F9542CF6ED80"/>
<incoming xmi:idref="EAID_873CF8C4_0192_4099_8F66_6B36FA760AB6"/>
<incoming xmi:idref="EAID_6B8D52FB_C522_4bda_BE10_B5080F9F0B0D"/>
<incoming xmi:idref="EAID_417A863C_D59C_4c5e_8F38_60B1DC36B077"/>
</node>
<node xmi:type="uml:DecisionNode" xmi:id="EAID_0D85B784_4393_429e_9BA1_7983BD7891CA" name="decision1" visibility="public">
<incoming xmi:idref="EAID_1FAD9B0B_04ED_4f6a_B359_8755C3A3CA03"/>
<outgoing xmi:idref="EAID_32A43FB9_D99D_4c3c_8382_D899FD995BA7"/>
<outgoing xmi:idref="EAID_2FECE2AE_6CA0_48a4_82AE_D743D257F37C"/>
</node>
</packagedElement>
</packagedElement>