1

Please help me to get an XML value using XPath. I have following XML code:

<packagedElement xmi:type="uml:Activity" name="Display Message" visibility="public" isReadOnly="false"/>
<packagedElement xmi:type='uml:Package' xmi:id='EAPK_358475EC_46AD_43eb_A00F_1A18E1B280D4' name='ATM Withdrawal'>
<node isReadOnly="false" name="Accept card" xmi:type="uml:Activity">
<ownedMember name="Model" visibility="public" xmi:type="uml:Package">

All I want is to get all @name value where xmi:type="uml:Activity". The results should be:

Display Message, Accept Card
kjhughes
  • 106,133
  • 27
  • 181
  • 240

1 Answers1

0

This XPath,

//*[@xmi:type="uml:Activity"]/@name

will select the name attributes for all elements with @xmi:type="uml:Activity".

Note that this presumes that you've bound the xmi namespace prefix to match its binding in the XML document. How you do that depends upon the language hosting XPath. For details, see How does XPath deal with XML namespaces?

kjhughes
  • 106,133
  • 27
  • 181
  • 240