I have a problem extracting the information I want from an EMF-model. I have created a meta-Model and from the model (.cim), expressed in XML, I want to generate code in the form of .mof (Managed Object Format). I therefore use XPath to extract information from the model and print it the way I like. But I can't seem to get the information I want...hopefully you can help me.

This is my simple CIM-model expressed in XML:

<?xml version="1.0" encoding="UTF-8"?>
<saabgroup:CModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:saabgroup="http://saabgroup.com/cim">
    <classes xsi:type="saabgroup:CClass" name="aClass">
      <qualifiers xsi:type="saabgroup:CClassConstraint" name="ClassConstraint">
      <qualifiers xsi:type="saabgroup:CAbstract" name="Abstract" subclass="Restricted"/>
      <qualifiers xsi:type="saabgroup:CDescription" name="Description" value="Desc.">

I want to extract the second value='two' from my first qualifier. Of what I have understood from XPath I tried the following:
<c:get select="/CModel/namespace/classes/qualifiers[1]/value[1]/text()">
But no result is returned. I have also tried many similar variants but everyone including text() fails. I did manage to get the first value from:
<c:get select="/CModel/namespace/classes/qualifiers[1]/@value">
But this implies that 'value' would be an attribute in the XML code, and I still can't get the second value. In the meta model value is expressed as a list of strings (For the qualifier of the type Description it is just a string).

Best regards

Hi ,

I think problem is in selecting element <saabgroup:CModel with prefix in the language in which you are trying to extract value.so first you declare name space in your file then use this.. <c:get select="/saabgroup:CModel/namespace/classes/qualifiers[1]/value[2]">
I am not sure because I don't know your language but logically it should work ...

however with xslt...we can extract required value easily by below code :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saabgroup="http://saabgroup.com/cim" version="1.0">
<xsl:template match="/">
<xsl:template match="saabgroup:CModel">
<xsl:value-of select="namespace/classes/qualifiers[1]/value[2]"/>

<xsl:template match="/">
<xsl:value-of select="saabgroup:CModel/namespace/classes/qualifiers[1]/value[2]"/>


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.