Hallo, ih habe hier eine mit StarUML erstellte XML Datei und will jetzt mithilfe von XPath jeden Knoten auslesen der beim Attribut name einen Inhlat hat.
[XML]<?xml version = "1.0" encoding = "UTF-8"?>
<XMI xmi.version = "1.1" xmlns:UML="href://org.omg/UML/1.3" timestamp = "Mon Sep 07 17:39:11 2009">
<XMI.header>
<XMI.documentation>
<XMI.owner></XMI.owner>
<XMI.contact></XMI.contact>
<XMI.exporter>StarUML.XMI-Addin</XMI.exporter>
<XMI.exporterVersion>1.0</XMI.exporterVersion>
<XMI.notice></XMI.notice>
</XMI.documentation>
<XMI.metamodel xmi.name = "UML" xmi.version = "1.3"/>
</XMI.header>
<XMI.content>
<UML:Model xmi.id="UMLProject.1">
<UML:Namespace.ownedElement>
<UMLackage xmi.id="UMLPackage.2" name="Package1" visibility="public" isSpecification="false" namespace="UMLProject.1" isRoot="false" isLeaf="false" isAbstract="false">
<UML:Namespace.ownedElement>
<UML:StateMachine xmi.id="UMLStateMachine.3" name="StateMachine1" visibility="public" isSpecification="false" context="UMLPackage.2">
<UML:StateMachine.top>
<UML:CompositeState xmi.id="UMLCompositeState.4" name="TOP" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" isConcurrent="false">
<UML:CompositeState.subvertex>
<UML:FinalState xmi.id="UMLFinalState.5" name="FinalState1" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.16"/>
<UML:SimpleState xmi.id="UMLCompositeState.6" name="0 - neuer Auftrag" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.17 UMLTransition.31 UMLTransition.32" incoming="UMLTransition.16 UMLTransition.28"/>
<UML:SimpleState xmi.id="UMLCompositeState.7" name="1 - Fahrt zum Kunden" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.18 UMLTransition.19" incoming="UMLTransition.17"/>
<UML:SimpleState xmi.id="UMLCompositeState.8" name="5 - Ankunft Kunde" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.20 UMLTransition.21" incoming="UMLTransition.18 UMLTransition.31"/>
<UML:SimpleState xmi.id="UMLCompositeState.9" name="6 - Beginn Entladung" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.22 UMLTransition.24" incoming="UMLTransition.20 UMLTransition.23 UMLTransition.25"/>
<UML:SimpleState xmi.id="UMLCompositeState.10" name="7 - Ende Entladung" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.23 UMLTransition.26 UMLTransition.27" incoming="UMLTransition.22"/>
<UML:SimpleState xmi.id="UMLCompositeState.11" name="8 - Beginn Kundenpause" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.25" incoming="UMLTransition.24"/>
<UML:SimpleState xmi.id="UMLCompositeState.12" name="15 - Auftrag erledigt" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.29" incoming="UMLTransition.26"/>
<UML:SimpleState xmi.id="UMLCompositeState.13" name="16 - Auftrag abbrechen" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.30" incoming="UMLTransition.19 UMLTransition.21 UMLTransition.27 UMLTransition.32"/>
<UML:FinalState xmi.id="UMLFinalState.14" name="FinalState2" visibility="public" isSpecification="false" container="UMLCompositeState.4" incoming="UMLTransition.29 UMLTransition.30"/>
<UMLseudostate xmi.id="UMLPseudostate.15" name="Initial1" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.28" kind="initial"/>
</UML:CompositeState.subvertex>
</UML:CompositeState>
</UML:StateMachine.top>
<UML:StateMachine.transitions>
<UML:Transition xmi.id="UMLTransition.16" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLFinalState.5" target="UMLCompositeState.6"/>
<UML:Transition xmi.id="UMLTransition.17" name="1; Auftrag angenommen, Dialog1" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.6" target="UMLCompositeState.7"/>
<UML:Transition xmi.id="UMLTransition.18" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.7" target="UMLCompositeState.8"/>
<UML:Transition xmi.id="UMLTransition.19" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.7" target="UMLCompositeState.13"/>
<UML:Transition xmi.id="UMLTransition.20" name="6, Entladung starten, Dialog3" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.8" target="UMLCompositeState.9"/>
<UML:Transition xmi.id="UMLTransition.21" name="16, Auftrag ablehnen, Dialog2" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.8" target="UMLCompositeState.13"/>
<UML:Transition xmi.id="UMLTransition.22" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.9" target="UMLCompositeState.10"/>
<UML:Transition xmi.id="UMLTransition.23" name="7, Entladung beendet, Dialog4" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.10" target="UMLCompositeState.9"/>
<UML:Transition xmi.id="UMLTransition.24" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.9" target="UMLCompositeState.11"/>
<UML:Transition xmi.id="UMLTransition.25" name="8, Pause, Dialog5" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.11" target="UMLCompositeState.9"/>
<UML:Transition xmi.id="UMLTransition.26" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.10" target="UMLCompositeState.12"/>
<UML:Transition xmi.id="UMLTransition.27" name="16, Auftrag ablehnen, Dialog2" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.10" target="UMLCompositeState.13"/>
<UML:Transition xmi.id="UMLTransition.28" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLPseudostate.15" target="UMLCompositeState.6"/>
<UML:Transition xmi.id="UMLTransition.29" name="Auftrag erledigt, Dialog6" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.12" target="UMLFinalState.14"/>
<UML:Transition xmi.id="UMLTransition.30" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.13" target="UMLFinalState.14"/>
<UML:Transition xmi.id="UMLTransition.31" name="5, Auftrag angenommen, Dialog1" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.6" target="UMLCompositeState.8"/>
<UML:Transition xmi.id="UMLTransition.32" name="16, Auftrag ablehnen, Dialog2" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.6" target="UMLCompositeState.13"/>
</UML:StateMachine.transitions>
</UML:StateMachine>
</UML:Namespace.ownedElement>
</UMLackage>
</UML:Namespace.ownedElement>
</UML:Model>
</XMI.content>
</XMI>
[/XML]
Momentan scheitere ich aber schon daran aus dieser UML Datei einen genauen Pfad auszulesen.
Habe mal probiert das Attribut name aus diesem Teil der XML auszulesen:
[XML]<UML:SimpleState xmi.id="UMLCompositeState.6" name="0 - neuer Auftrag" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.17 UMLTransition.31 UMLTransition.32" incoming="UMLTransition.16 UMLTransition.28"/>[/XML]
Diesen Pfad habe ich dafür verwendet. Er funktioniert aber nicht.
Ich bräuchte jetzt eure Hilfe. Kann mir jemand helfen einen Pfad so anzulegen, dass er mir alle Attribute durchsucht und immer dann wenn er ein Attribut name findet welches einen Inhalt hat, soll er diesen Inhalt in eine andere XML Datei schreiben.
Es würde auch passen wenn er einfach nur von jedem
[XML] <UML:SimpleState>[/XML]
das Attribut name auslesen würde und dann in ein neues Dokument speichert.
Vielen Dank schon mal
[XML]<?xml version = "1.0" encoding = "UTF-8"?>
<XMI xmi.version = "1.1" xmlns:UML="href://org.omg/UML/1.3" timestamp = "Mon Sep 07 17:39:11 2009">
<XMI.header>
<XMI.documentation>
<XMI.owner></XMI.owner>
<XMI.contact></XMI.contact>
<XMI.exporter>StarUML.XMI-Addin</XMI.exporter>
<XMI.exporterVersion>1.0</XMI.exporterVersion>
<XMI.notice></XMI.notice>
</XMI.documentation>
<XMI.metamodel xmi.name = "UML" xmi.version = "1.3"/>
</XMI.header>
<XMI.content>
<UML:Model xmi.id="UMLProject.1">
<UML:Namespace.ownedElement>
<UMLackage xmi.id="UMLPackage.2" name="Package1" visibility="public" isSpecification="false" namespace="UMLProject.1" isRoot="false" isLeaf="false" isAbstract="false">
<UML:Namespace.ownedElement>
<UML:StateMachine xmi.id="UMLStateMachine.3" name="StateMachine1" visibility="public" isSpecification="false" context="UMLPackage.2">
<UML:StateMachine.top>
<UML:CompositeState xmi.id="UMLCompositeState.4" name="TOP" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" isConcurrent="false">
<UML:CompositeState.subvertex>
<UML:FinalState xmi.id="UMLFinalState.5" name="FinalState1" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.16"/>
<UML:SimpleState xmi.id="UMLCompositeState.6" name="0 - neuer Auftrag" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.17 UMLTransition.31 UMLTransition.32" incoming="UMLTransition.16 UMLTransition.28"/>
<UML:SimpleState xmi.id="UMLCompositeState.7" name="1 - Fahrt zum Kunden" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.18 UMLTransition.19" incoming="UMLTransition.17"/>
<UML:SimpleState xmi.id="UMLCompositeState.8" name="5 - Ankunft Kunde" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.20 UMLTransition.21" incoming="UMLTransition.18 UMLTransition.31"/>
<UML:SimpleState xmi.id="UMLCompositeState.9" name="6 - Beginn Entladung" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.22 UMLTransition.24" incoming="UMLTransition.20 UMLTransition.23 UMLTransition.25"/>
<UML:SimpleState xmi.id="UMLCompositeState.10" name="7 - Ende Entladung" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.23 UMLTransition.26 UMLTransition.27" incoming="UMLTransition.22"/>
<UML:SimpleState xmi.id="UMLCompositeState.11" name="8 - Beginn Kundenpause" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.25" incoming="UMLTransition.24"/>
<UML:SimpleState xmi.id="UMLCompositeState.12" name="15 - Auftrag erledigt" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.29" incoming="UMLTransition.26"/>
<UML:SimpleState xmi.id="UMLCompositeState.13" name="16 - Auftrag abbrechen" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.30" incoming="UMLTransition.19 UMLTransition.21 UMLTransition.27 UMLTransition.32"/>
<UML:FinalState xmi.id="UMLFinalState.14" name="FinalState2" visibility="public" isSpecification="false" container="UMLCompositeState.4" incoming="UMLTransition.29 UMLTransition.30"/>
<UMLseudostate xmi.id="UMLPseudostate.15" name="Initial1" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.28" kind="initial"/>
</UML:CompositeState.subvertex>
</UML:CompositeState>
</UML:StateMachine.top>
<UML:StateMachine.transitions>
<UML:Transition xmi.id="UMLTransition.16" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLFinalState.5" target="UMLCompositeState.6"/>
<UML:Transition xmi.id="UMLTransition.17" name="1; Auftrag angenommen, Dialog1" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.6" target="UMLCompositeState.7"/>
<UML:Transition xmi.id="UMLTransition.18" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.7" target="UMLCompositeState.8"/>
<UML:Transition xmi.id="UMLTransition.19" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.7" target="UMLCompositeState.13"/>
<UML:Transition xmi.id="UMLTransition.20" name="6, Entladung starten, Dialog3" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.8" target="UMLCompositeState.9"/>
<UML:Transition xmi.id="UMLTransition.21" name="16, Auftrag ablehnen, Dialog2" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.8" target="UMLCompositeState.13"/>
<UML:Transition xmi.id="UMLTransition.22" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.9" target="UMLCompositeState.10"/>
<UML:Transition xmi.id="UMLTransition.23" name="7, Entladung beendet, Dialog4" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.10" target="UMLCompositeState.9"/>
<UML:Transition xmi.id="UMLTransition.24" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.9" target="UMLCompositeState.11"/>
<UML:Transition xmi.id="UMLTransition.25" name="8, Pause, Dialog5" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.11" target="UMLCompositeState.9"/>
<UML:Transition xmi.id="UMLTransition.26" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.10" target="UMLCompositeState.12"/>
<UML:Transition xmi.id="UMLTransition.27" name="16, Auftrag ablehnen, Dialog2" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.10" target="UMLCompositeState.13"/>
<UML:Transition xmi.id="UMLTransition.28" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLPseudostate.15" target="UMLCompositeState.6"/>
<UML:Transition xmi.id="UMLTransition.29" name="Auftrag erledigt, Dialog6" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.12" target="UMLFinalState.14"/>
<UML:Transition xmi.id="UMLTransition.30" name="" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.13" target="UMLFinalState.14"/>
<UML:Transition xmi.id="UMLTransition.31" name="5, Auftrag angenommen, Dialog1" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.6" target="UMLCompositeState.8"/>
<UML:Transition xmi.id="UMLTransition.32" name="16, Auftrag ablehnen, Dialog2" visibility="public" isSpecification="false" stateMachine="UMLStateMachine.3" source="UMLCompositeState.6" target="UMLCompositeState.13"/>
</UML:StateMachine.transitions>
</UML:StateMachine>
</UML:Namespace.ownedElement>
</UMLackage>
</UML:Namespace.ownedElement>
</UML:Model>
</XMI.content>
</XMI>
[/XML]
Momentan scheitere ich aber schon daran aus dieser UML Datei einen genauen Pfad auszulesen.
Habe mal probiert das Attribut name aus diesem Teil der XML auszulesen:
[XML]<UML:SimpleState xmi.id="UMLCompositeState.6" name="0 - neuer Auftrag" visibility="public" isSpecification="false" container="UMLCompositeState.4" outgoing="UMLTransition.17 UMLTransition.31 UMLTransition.32" incoming="UMLTransition.16 UMLTransition.28"/>[/XML]
Java:
XPathExpression expr = xpath.compile("UML:Namespace.ownedElement//UML:StateMachine xmi.//UML:StateMachine.top//UML:CompositeState xmi.//UML:CompositeState.subvertex//UML:FinalState xmi.//UML:SimpleState xmi.//@name");
Diesen Pfad habe ich dafür verwendet. Er funktioniert aber nicht.
Ich bräuchte jetzt eure Hilfe. Kann mir jemand helfen einen Pfad so anzulegen, dass er mir alle Attribute durchsucht und immer dann wenn er ein Attribut name findet welches einen Inhalt hat, soll er diesen Inhalt in eine andere XML Datei schreiben.
Es würde auch passen wenn er einfach nur von jedem
[XML] <UML:SimpleState>[/XML]
das Attribut name auslesen würde und dann in ein neues Dokument speichert.
Vielen Dank schon mal
Zuletzt bearbeitet: