Galera estou lendo esse XML. A minha dificuldade é saber como faço para pegar o valor do atributo name do elemento UML:Class. Gostaria de saber como faço para pegar o atributo. Estou usando XPath
<?xml version = '1.0' encoding = 'UTF-8' ?>
<XMI xmi.version = '1.2' xmlns:UML = 'org.omg.xmi.namespace.UML' timestamp = 'Tue Aug 09 15:38:38 BRT 2011'>
<XMI.header>
<XMI.documentation>
<XMI.exporter>ArgoUML (using Netbeans XMI Writer version 1.0)</XMI.exporter>
<XMI.exporterVersion>0.32.2(6) revised on $Date: 2010-01-11 22:20:14 +0100 (Mon, 11 Jan 2010) $ </XMI.exporterVersion>
</XMI.documentation>
<XMI.metamodel xmi.name="UML" xmi.version="1.4"/>
</XMI.header>
<XMI.content>
<UML:Model xmi.id = '123'
name = 'modeloSemNome' isSpecification = 'false' isRoot = 'false' isLeaf = 'false'
isAbstract = 'false'>
<UML:Namespace.ownedElement>
<UML:Class xmi.id = '127-0-1-1--57e073b3:131afce9b99:-8000:0000000000000866'
name = 'Carro' visibility = 'public' isSpecification = 'false' isRoot = 'false'
isLeaf = 'false' isAbstract = 'false' isActive = 'false'/>
</UML:Namespace.ownedElement>
</UML:Model>
</XMI.content>
</XMI>
Usando o seguinte código:
DocumentBuilderFactory dom = DocumentBuilderFactory.newInstance();
dom.setNamespaceAware(true);
DocumentBuilder builder = dom.newDocumentBuilder();
Document document = builder.parse("/home/rafael/argo.xmi");
XPath xPath = XPathFactory.newInstance().newXPath();
XPathExpression exp = xPath.compile("//XMI.content/UML:Model/UML:Namespace.ownedElement/UML:Class/@name");
Object o = exp.evaluate(document, XPathConstants.NODESET);
NodeList nodes = (NodeList) o;
for(int i = 0; i < nodes.getLength(); i++)
System.out.println(nodes.item(i).getNodeValue());