문제

I want to get attribute "name" of element "UML:UseCase" from this XMLfile.

<?xml version = "1.0" encoding = "UTF-8"?>
<XMI xmi.version = "1.1" xmlns:UML="href://org.omg/UML/1.3" timestamp = "Fri Nov 16 11:47:6 2012">
<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>
    <UML:Model xmi.id="UMLModel.2" name="Use Case Model" visibility="public" isSpecification="false" namespace="UMLProject.1" isRoot="false" isLeaf="false" isAbstract="false">
      <UML:Namespace.ownedElement>
        <UML:Package xmi.id="UMLPackage.3" name="Purchasing" visibility="public" isSpecification="false" namespace="UMLModel.2" isRoot="false" isLeaf="false" isAbstract="false">
          <UML:Namespace.ownedElement>
            <UML:UseCase xmi.id="UMLUseCase.4" name="Place order" visibility="public" isSpecification="false" namespace="UMLPackage.3" isRoot="false" isLeaf="false" isAbstract="false" participant="UMLAssociationEnd.40" extend2="UMLExtend.47 UMLExtend.48" include="UMLInclude.25 UMLInclude.44 UMLInclude.45"/>
            <UML:UseCase xmi.id="UMLUseCase.5" name="Place order via Web site" visibility="public" isSpecification="false" namespace="UMLPackage.3" isRoot="false" isLeaf="false" isAbstract="false" extend="UMLExtend.48"/>
            <UML:UseCase xmi.id="UMLUseCase.6" name="Place order via Application" visibility="public" isSpecification="false" namespace="UMLPackage.3" isRoot="false" isLeaf="false" isAbstract="false" extend="UMLExtend.47"/>
            <UML:UseCase xmi.id="UMLUseCase.7" name="Browse catalog" visibility="public" isSpecification="false" namespace="UMLPackage.3" isRoot="false" isLeaf="false" isAbstract="false" participant="UMLAssociationEnd.43"/>
            <UML:UseCase xmi.id="UMLUseCase.8" name="Confirm shipment" visibility="public" isSpecification="false" namespace="UMLPackage.3" isRoot="false" isLeaf="false" isAbstract="false"/>
            <UML:Actor xmi.id="UMLActor.9" name="Customer" visibility="public" isSpecification="false" namespace="UMLPackage.3" isRoot="false" isLeaf="false" isAbstract="false" participant="UMLAssociationEnd.39 UMLAssociationEnd.42"/>
            <UML:Stereotype xmi.id="X.55" name="Common feature" extendedElement="UMLPackage.3"/>
            <UML:Stereotype xmi.id="X.56" name="Common use case" extendedElement="UMLUseCase.4 UMLUseCase.7 UMLUseCase.8"/>
            <UML:Stereotype xmi.id="X.57" name="Alternative use case" extendedElement="UMLUseCase.5 UMLUseCase.6"/>
          </UML:Namespace.ownedElement>
        </UML:Package>
......

My expected result.

Place order
Place order via Web site
Place order via Application
Browse catalog
Confirm shipment

thank you

도움이 되었습니까?

해결책

Too much effort to write the program for you... but you will want to either investigate XPaths using namespaces:

XPathFactory.compile("//UML:UseCase/@name", Filters.attribute(), null,
         Namespace.getNamespace("UML", "href://org.omg/UML/1.3"));

or navigating directly with Namespaces:

Parent.getChildren(name, Namespace).

Your issue is that you need to access all the UML-prefixed content with the namespace Namespace.getNamespace("UML", "href://org.omg/UML/1.3");

Rolf

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top