Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » namespaceURI retrieval
namespaceURI retrieval [message #421916] Mon, 18 August 2008 12:26 Go to next message
J. Rietz is currently offline J. RietzFriend
Messages: 40
Registered: July 2009
Member
Hi,

I have code for retrieval of namespaceURI of a resource (see code snippet
below).
This code works fine, but now I need to find the other referenced
namespaceURI's in similar way.

For instance if having below root:
<rbc:RbcAppl xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rbc="http://www.a.b/data/rbc/v8"
xmlns:rbc_bv="http://www.a.b/data/rbc_bv/v3"
xmi:id="_hFOnoCsXEd2CsoTXrynoRw" projectVersion="3">
code snippet below successfully gets the 'rbc' namespaceURI
"http://www.a.b/data/rbc/v8".

But how do I manage to get the 'rbc_bv' namespaceURI??

* * * * *
Code snippet:
..
..
XMLResource xmlResource = load(uri, inputStream, options, context);
EList<EObject> contents = xmlResource.getContents();
if (!contents.isEmpty()) {
EObject eObject = contents.get(0);
if (eObject instanceof XMLTypeDocumentRoot) {
XMLTypeDocumentRoot documentRoot = (XMLTypeDocumentRoot) eObject;
EList<EObject> rootContents = documentRoot.eContents();
String rootElementName = null;
String rootElementNamespace = null;
if (!rootContents.isEmpty()) {
EObject root = rootContents.get(0);
EReference eContainmentFeature = root.eContainmentFeature();
rootElementName = eContainmentFeature.getName();
rootElementNamespace =
ExtendedMetaData.INSTANCE.getNamespace(eContainmentFeature);
}
return rootElementNamespace;
}
}
return null;
..
..


Regards,
Joachim
Re: namespaceURI retrieval [message #421917 is a reply to message #421916] Mon, 18 August 2008 12:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Joachim,

Comments below.


Joachim Rietz wrote:
> Hi,
>
> I have code for retrieval of namespaceURI of a resource (see code
> snippet below).
> This code works fine, but now I need to find the other referenced
> namespaceURI's in similar way.
>
> For instance if having below root:
> <rbc:RbcAppl xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:rbc="http://www.a.b/data/rbc/v8"
> xmlns:rbc_bv="http://www.a.b/data/rbc_bv/v3"
> xmi:id="_hFOnoCsXEd2CsoTXrynoRw" projectVersion="3">
> code snippet below successfully gets the 'rbc' namespaceURI
> "http://www.a.b/data/rbc/v8".
>
> But how do I manage to get the 'rbc_bv' namespaceURI??
>
> * * * * *
> Code snippet:
> .
> .
> XMLResource xmlResource = load(uri, inputStream, options, context);
Are you parsing the whole document but you only need to get the
information for the root element? EMF has support for content types now
that handle this quite efficiently. You might want to look at how
XMLContentHandlerImpl does this...
> EList<EObject> contents = xmlResource.getContents();
> if (!contents.isEmpty()) {
> EObject eObject = contents.get(0);
> if (eObject instanceof XMLTypeDocumentRoot) {
> XMLTypeDocumentRoot documentRoot = (XMLTypeDocumentRoot) eObject;
> EList<EObject> rootContents = documentRoot.eContents();
> String rootElementName = null;
> String rootElementNamespace = null;
> if (!rootContents.isEmpty()) {
> EObject root = rootContents.get(0);
> EReference eContainmentFeature = root.eContainmentFeature();
> rootElementName = eContainmentFeature.getName();
> rootElementNamespace =
> ExtendedMetaData.INSTANCE.getNamespace(eContainmentFeature);
You can look at documentRoot.getXMLNSPrefixMap(). It will have mappings
for all the xmlns declarations in the root element.
> }
> return rootElementNamespace;
> }
> }
> return null;
> .
> .
>
>
> Regards,
> Joachim
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: namespaceURI retrieval [message #421919 is a reply to message #421917] Mon, 18 August 2008 13:19 Go to previous messageGo to next message
J. Rietz is currently offline J. RietzFriend
Messages: 40
Registered: July 2009
Member
Ed,
I've tried the documentRoot.getXMLNSPrefixMap(), but it returns an empty
map...
Are there some stuff to do to get this working properly?

/Joachim

Ed Merks wrote:

> Joachim,

> Comments below.


> Joachim Rietz wrote:
>> Hi,
>>
>> I have code for retrieval of namespaceURI of a resource (see code
>> snippet below).
>> This code works fine, but now I need to find the other referenced
>> namespaceURI's in similar way.
>>
>> For instance if having below root:
>> <rbc:RbcAppl xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:rbc="http://www.a.b/data/rbc/v8"
>> xmlns:rbc_bv="http://www.a.b/data/rbc_bv/v3"
>> xmi:id="_hFOnoCsXEd2CsoTXrynoRw" projectVersion="3">
>> code snippet below successfully gets the 'rbc' namespaceURI
>> "http://www.a.b/data/rbc/v8".
>>
>> But how do I manage to get the 'rbc_bv' namespaceURI??
>>
>> * * * * *
>> Code snippet:
>> .
>> .
>> XMLResource xmlResource = load(uri, inputStream, options, context);
> Are you parsing the whole document but you only need to get the
> information for the root element? EMF has support for content types now
> that handle this quite efficiently. You might want to look at how
> XMLContentHandlerImpl does this...
>> EList<EObject> contents = xmlResource.getContents();
>> if (!contents.isEmpty()) {
>> EObject eObject = contents.get(0);
>> if (eObject instanceof XMLTypeDocumentRoot) {
>> XMLTypeDocumentRoot documentRoot = (XMLTypeDocumentRoot) eObject;
>> EList<EObject> rootContents = documentRoot.eContents();
>> String rootElementName = null;
>> String rootElementNamespace = null;
>> if (!rootContents.isEmpty()) {
>> EObject root = rootContents.get(0);
>> EReference eContainmentFeature = root.eContainmentFeature();
>> rootElementName = eContainmentFeature.getName();
>> rootElementNamespace =
>> ExtendedMetaData.INSTANCE.getNamespace(eContainmentFeature);
> You can look at documentRoot.getXMLNSPrefixMap(). It will have mappings
> for all the xmlns declarations in the root element.
>> }
>> return rootElementNamespace;
>> }
>> }
>> return null;
>> .
>> .
>>
>>
>> Regards,
>> Joachim
>>
Re: namespaceURI retrieval [message #421922 is a reply to message #421919] Mon, 18 August 2008 13:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000006030103080601010500
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Joachim,

I'd expect this XMLHandler logic to kick in and do the trick:

| *public **void *endDocument()
{
*if *(deferredExtent != *null*)
{
extent.addAll(deferredExtent);
}

// Pretend there is an xmlns="" because we really need to ensure that the null prefix
// isn't used to denote something other than the null namespace.
//
*if *(usedNullNamespacePackage)
{
helper.addPrefix("", "");
}
helper.recordPrefixToURIMapping();
helper.popContext();
handleForwardReferences(*true*);

*if *(disableNotify)
{
*for *(Iterator<?> i = EcoreUtil.getAllContents(xmlResource.getContents(), *false*); i.hasNext(); )
{
EObject eObject = (EObject)i.next();
eObject.eSetDeliver(*true*);
}
}

*if *(extendedMetaData != *null*)
{
*if *(extent.size() == 1)
{
EObject root = extent.get(0);
recordNamespacesSchemaLocations(root);
}

*if *(DEBUG_DEMANDED_PACKAGES)
{
// EATM temporary for debug purposes only.
//
Collection<EPackage> demandedPackages = EcoreUtil.copyAll(extendedMetaData.demandedPackages());
*for *(EPackage ePackage : demandedPackages)
{
ePackage.setName(ePackage.getNsURI());
}
extent.addAll(demandedPackages);
}
}
}

*protected *EMap<String, String> recordNamespacesSchemaLocations(EObject root)
{
EClass eClass = root.eClass();
EReference xmlnsPrefixMapFeature = extendedMetaData.getXMLNSPrefixMapFeature(eClass);
EMap<String, String> xmlnsPrefixMap = *null*;
*if *(xmlnsPrefixMapFeature != *null*)
{
@SuppressWarnings("unchecked") EMap<String, String> newXMLNSPrefixMap = (EMap<String, String>)root.eGet(xmlnsPrefixMapFeature);
xmlnsPrefixMap = newXMLNSPrefixMap;
xmlnsPrefixMap.putAll(helper.getPrefixToNamespaceMap());
}

*if *(urisToLocations != *null*)
{
EReference xsiSchemaLocationMapFeature = extendedMetaData.getXSISchemaLocationMapFeature(eClass);
*if *(xsiSchemaLocationMapFeature != *null*)
{
@SuppressWarnings("unchecked") EMap<String, String> newXSISchemaLocationMap = (EMap<String, String>)root.eGet(xsiSchemaLocationMapFeature);
EMap<String, String> xsiSchemaLocationMap = newXSISchemaLocationMap;
*for *(Map.Entry<String, URI> entry : urisToLocations.entrySet())
{
xsiSchemaLocationMap.put(entry.getKey(), entry.getValue().toString());
}
}
}
*return *xmlnsPrefixMap;
}|


Joachim Rietz wrote:
> Ed, I've tried the documentRoot.getXMLNSPrefixMap(), but it returns an
> empty map...
> Are there some stuff to do to get this working properly?
>
> /Joachim
>
> Ed Merks wrote:
>
>> Joachim,
>
>> Comments below.
>
>
>> Joachim Rietz wrote:
>>> Hi,
>>>
>>> I have code for retrieval of namespaceURI of a resource (see code
>>> snippet below).
>>> This code works fine, but now I need to find the other referenced
>>> namespaceURI's in similar way.
>>>
>>> For instance if having below root:
>>> <rbc:RbcAppl xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xmlns:rbc="http://www.a.b/data/rbc/v8"
>>> xmlns:rbc_bv="http://www.a.b/data/rbc_bv/v3"
>>> xmi:id="_hFOnoCsXEd2CsoTXrynoRw" projectVersion="3">
>>> code snippet below successfully gets the 'rbc' namespaceURI
>>> "http://www.a.b/data/rbc/v8".
>>>
>>> But how do I manage to get the 'rbc_bv' namespaceURI??
>>>
>>> * * * * *
>>> Code snippet:
>>> .
>>> .
>>> XMLResource xmlResource = load(uri, inputStream, options, context);
>> Are you parsing the whole document but you only need to get the
>> information for the root element? EMF has support for content types
>> now that handle this quite efficiently. You might want to look at
>> how XMLContentHandlerImpl does this...
>>> EList<EObject> contents = xmlResource.getContents();
>>> if (!contents.isEmpty()) {
>>> EObject eObject = contents.get(0);
>>> if (eObject instanceof XMLTypeDocumentRoot) {
>>> XMLTypeDocumentRoot documentRoot = (XMLTypeDocumentRoot)
>>> eObject;
>>> EList<EObject> rootContents = documentRoot.eContents();
>>> String rootElementName = null;
>>> String rootElementNamespace = null;
>>> if (!rootContents.isEmpty()) {
>>> EObject root = rootContents.get(0);
>>> EReference eContainmentFeature = root.eContainmentFeature();
>>> rootElementName = eContainmentFeature.getName();
>>> rootElementNamespace =
>>> ExtendedMetaData.INSTANCE.getNamespace(eContainmentFeature);
>> You can look at documentRoot.getXMLNSPrefixMap(). It will have
>> mappings for all the xmlns declarations in the root element.
>>> }
>>> return rootElementNamespace;
>>> }
>>> }
>>> return null;
>>> .
>>> .
>>>
>>>
>>> Regards,
>>> Joachim
>>>
>
>

--------------000006030103080601010500
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Joachim,<br>
<br>
I'd expect this XMLHandler logic to kick in and do the trick:<br>
<blockquote>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<!-- ======================================================== --><!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td align="left" nowrap="nowrap"
valign="top"> <code><font color="#ffffff">


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: namespaceURI retrieval [message #421923 is a reply to message #421922] Mon, 18 August 2008 14:14 Go to previous messageGo to next message
J. Rietz is currently offline J. RietzFriend
Messages: 40
Registered: July 2009
Member
Hi again,

Ehh, I'm not sure if I missed something obvious here, but I really don't
know what to do with the code you provided below...
Shall I add it in my code, where? Or how shall I use it?

/Joachim

Ed Merks wrote:

> Joachim,

> I'd expect this XMLHandler logic to kick in and do the trick:

> | *public **void *endDocument()
> {
> *if *(deferredExtent != *null*)
> {
> extent.addAll(deferredExtent);
> }

> // Pretend there is an xmlns="" because we really need to ensure
that the null prefix
> // isn't used to denote something other than the null namespace.
> //
> *if *(usedNullNamespacePackage)
> {
> helper.addPrefix("", "");
> }
> helper.recordPrefixToURIMapping();
> helper.popContext();
> handleForwardReferences(*true*);

> *if *(disableNotify)
> {
> *for *(Iterator<?> i =
EcoreUtil.getAllContents(xmlResource.getContents(), *false*); i.hasNext(); )
> {
> EObject eObject = (EObject)i.next();
> eObject.eSetDeliver(*true*);
> }
> }

> *if *(extendedMetaData != *null*)
> {
> *if *(extent.size() == 1)
> {
> EObject root = extent.get(0);
> recordNamespacesSchemaLocations(root);
> }

> *if *(DEBUG_DEMANDED_PACKAGES)
> {
> // EATM temporary for debug purposes only.
> //
> Collection<EPackage> demandedPackages =
EcoreUtil.copyAll(extendedMetaData.demandedPackages());
> *for *(EPackage ePackage : demandedPackages)
> {
> ePackage.setName(ePackage.getNsURI());
> }
> extent.addAll(demandedPackages);
> }
> }
> }

> *protected *EMap<String, String>
recordNamespacesSchemaLocations(EObject root)
> {
> EClass eClass = root.eClass();
> EReference xmlnsPrefixMapFeature =
extendedMetaData.getXMLNSPrefixMapFeature(eClass);
> EMap<String, String> xmlnsPrefixMap = *null*;
> *if *(xmlnsPrefixMapFeature != *null*)
> {
> @SuppressWarnings("unchecked") EMap<String, String>
newXMLNSPrefixMap = (EMap<String, String>)root.eGet(xmlnsPrefixMapFeature);
> xmlnsPrefixMap = newXMLNSPrefixMap;
> xmlnsPrefixMap.putAll(helper.getPrefixToNamespaceMap());
> }

> *if *(urisToLocations != *null*)
> {
> EReference xsiSchemaLocationMapFeature =
extendedMetaData.getXSISchemaLocationMapFeature(eClass);
> *if *(xsiSchemaLocationMapFeature != *null*)
> {
> @SuppressWarnings("unchecked") EMap<String, String>
newXSISchemaLocationMap = (EMap<String,
String>)root.eGet(xsiSchemaLocationMapFeature);
> EMap<String, String> xsiSchemaLocationMap =
newXSISchemaLocationMap;
> *for *(Map.Entry<String, URI> entry : urisToLocations.entrySet())
> {
> xsiSchemaLocationMap.put(entry.getKey(),
entry.getValue().toString());
> }
> }
> }
> *return *xmlnsPrefixMap;
> }|


> Joachim Rietz wrote:
>> Ed, I've tried the documentRoot.getXMLNSPrefixMap(), but it returns an
>> empty map...
>> Are there some stuff to do to get this working properly?
>>
>> /Joachim
>>
>> Ed Merks wrote:
>>
>>> Joachim,
>>
>>> Comments below.
>>
>>
>>> Joachim Rietz wrote:
>>>> Hi,
>>>>
>>>> I have code for retrieval of namespaceURI of a resource (see code
>>>> snippet below).
>>>> This code works fine, but now I need to find the other referenced
>>>> namespaceURI's in similar way.
>>>>
>>>> For instance if having below root:
>>>> <rbc:RbcAppl xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>> xmlns:rbc="http://www.a.b/data/rbc/v8"
>>>> xmlns:rbc_bv="http://www.a.b/data/rbc_bv/v3"
>>>> xmi:id="_hFOnoCsXEd2CsoTXrynoRw" projectVersion="3">
>>>> code snippet below successfully gets the 'rbc' namespaceURI
>>>> "http://www.a.b/data/rbc/v8".
>>>>
>>>> But how do I manage to get the 'rbc_bv' namespaceURI??
>>>>
>>>> * * * * *
>>>> Code snippet:
>>>> .
>>>> .
>>>> XMLResource xmlResource = load(uri, inputStream, options, context);
>>> Are you parsing the whole document but you only need to get the
>>> information for the root element? EMF has support for content types
>>> now that handle this quite efficiently. You might want to look at
>>> how XMLContentHandlerImpl does this...
>>>> EList<EObject> contents = xmlResource.getContents();
>>>> if (!contents.isEmpty()) {
>>>> EObject eObject = contents.get(0);
>>>> if (eObject instanceof XMLTypeDocumentRoot) {
>>>> XMLTypeDocumentRoot documentRoot = (XMLTypeDocumentRoot)
>>>> eObject;
>>>> EList<EObject> rootContents = documentRoot.eContents();
>>>> String rootElementName = null;
>>>> String rootElementNamespace = null;
>>>> if (!rootContents.isEmpty()) {
>>>> EObject root = rootContents.get(0);
>>>> EReference eContainmentFeature = root.eContainmentFeature();
>>>> rootElementName = eContainmentFeature.getName();
>>>> rootElementNamespace =
>>>> ExtendedMetaData.INSTANCE.getNamespace(eContainmentFeature);
>>> You can look at documentRoot.getXMLNSPrefixMap(). It will have
>>> mappings for all the xmlns declarations in the root element.
>>>> }
>>>> return rootElementNamespace;
>>>> }
>>>> }
>>>> return null;
>>>> .
>>>> .
>>>>
>>>>
>>>> Regards,
>>>> Joachim
>>>>
>>
>>
Re: namespaceURI retrieval [message #421924 is a reply to message #421923] Mon, 18 August 2008 14:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Joachim,

That's code which already exists in XMLHandler and which should be
kicking in during the processing of your document. You'll want to see a
breakpoint to see why it's not going there...


Joachim Rietz wrote:
> Hi again,
>
> Ehh, I'm not sure if I missed something obvious here, but I really
> don't know what to do with the code you provided below...
> Shall I add it in my code, where? Or how shall I use it?
>
> /Joachim
>
> Ed Merks wrote:
>
>> Joachim,
>
>> I'd expect this XMLHandler logic to kick in and do the trick:
>
>> | *public **void *endDocument()
>> {
>> *if *(deferredExtent != *null*)
>> {
>> extent.addAll(deferredExtent);
>> }
>
>> // Pretend there is an xmlns="" because we really need to ensure
> that the null prefix
>> // isn't used to denote something other than the null namespace.
>> //
>> *if *(usedNullNamespacePackage)
>> {
>> helper.addPrefix("", "");
>> }
>> helper.recordPrefixToURIMapping();
>> helper.popContext();
>> handleForwardReferences(*true*);
>
>> *if *(disableNotify) {
>> *for *(Iterator<?> i =
> EcoreUtil.getAllContents(xmlResource.getContents(), *false*);
> i.hasNext(); )
>> {
>> EObject eObject = (EObject)i.next();
>> eObject.eSetDeliver(*true*);
>> }
>> }
>
>> *if *(extendedMetaData != *null*)
>> {
>> *if *(extent.size() == 1)
>> {
>> EObject root = extent.get(0);
>> recordNamespacesSchemaLocations(root); }
>
>> *if *(DEBUG_DEMANDED_PACKAGES)
>> {
>> // EATM temporary for debug purposes only.
>> //
>> Collection<EPackage> demandedPackages =
> EcoreUtil.copyAll(extendedMetaData.demandedPackages());
>> *for *(EPackage ePackage : demandedPackages)
>> {
>> ePackage.setName(ePackage.getNsURI());
>> }
>> extent.addAll(demandedPackages);
>> }
>> }
>> }
>
>> *protected *EMap<String, String>
> recordNamespacesSchemaLocations(EObject root)
>> {
>> EClass eClass = root.eClass();
>> EReference xmlnsPrefixMapFeature =
> extendedMetaData.getXMLNSPrefixMapFeature(eClass);
>> EMap<String, String> xmlnsPrefixMap = *null*;
>> *if *(xmlnsPrefixMapFeature != *null*)
>> {
>> @SuppressWarnings("unchecked") EMap<String, String>
> newXMLNSPrefixMap = (EMap<String,
> String>)root.eGet(xmlnsPrefixMapFeature);
>> xmlnsPrefixMap = newXMLNSPrefixMap;
>> xmlnsPrefixMap.putAll(helper.getPrefixToNamespaceMap());
>> }
>
>> *if *(urisToLocations != *null*)
>> {
>> EReference xsiSchemaLocationMapFeature =
> extendedMetaData.getXSISchemaLocationMapFeature(eClass);
>> *if *(xsiSchemaLocationMapFeature != *null*)
>> {
>> @SuppressWarnings("unchecked") EMap<String, String>
> newXSISchemaLocationMap = (EMap<String,
> String>)root.eGet(xsiSchemaLocationMapFeature);
>> EMap<String, String> xsiSchemaLocationMap =
> newXSISchemaLocationMap;
>> *for *(Map.Entry<String, URI> entry :
>> urisToLocations.entrySet())
>> {
>> xsiSchemaLocationMap.put(entry.getKey(),
> entry.getValue().toString());
>> }
>> }
>> }
>> *return *xmlnsPrefixMap;
>> }|
>
>
>> Joachim Rietz wrote:
>>> Ed, I've tried the documentRoot.getXMLNSPrefixMap(), but it returns
>>> an empty map...
>>> Are there some stuff to do to get this working properly?
>>>
>>> /Joachim
>>>
>>> Ed Merks wrote:
>>>
>>>> Joachim,
>>>
>>>> Comments below.
>>>
>>>
>>>> Joachim Rietz wrote:
>>>>> Hi,
>>>>>
>>>>> I have code for retrieval of namespaceURI of a resource (see code
>>>>> snippet below).
>>>>> This code works fine, but now I need to find the other referenced
>>>>> namespaceURI's in similar way.
>>>>>
>>>>> For instance if having below root:
>>>>> <rbc:RbcAppl xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
>>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>>> xmlns:rbc="http://www.a.b/data/rbc/v8"
>>>>> xmlns:rbc_bv="http://www.a.b/data/rbc_bv/v3"
>>>>> xmi:id="_hFOnoCsXEd2CsoTXrynoRw" projectVersion="3">
>>>>> code snippet below successfully gets the 'rbc' namespaceURI
>>>>> "http://www.a.b/data/rbc/v8".
>>>>>
>>>>> But how do I manage to get the 'rbc_bv' namespaceURI??
>>>>>
>>>>> * * * * *
>>>>> Code snippet:
>>>>> .
>>>>> .
>>>>> XMLResource xmlResource = load(uri, inputStream, options, context);
>>>> Are you parsing the whole document but you only need to get the
>>>> information for the root element? EMF has support for content
>>>> types now that handle this quite efficiently. You might want to
>>>> look at how XMLContentHandlerImpl does this...
>>>>> EList<EObject> contents = xmlResource.getContents();
>>>>> if (!contents.isEmpty()) {
>>>>> EObject eObject = contents.get(0);
>>>>> if (eObject instanceof XMLTypeDocumentRoot) {
>>>>> XMLTypeDocumentRoot documentRoot = (XMLTypeDocumentRoot)
>>>>> eObject;
>>>>> EList<EObject> rootContents = documentRoot.eContents();
>>>>> String rootElementName = null;
>>>>> String rootElementNamespace = null;
>>>>> if (!rootContents.isEmpty()) {
>>>>> EObject root = rootContents.get(0);
>>>>> EReference eContainmentFeature =
>>>>> root.eContainmentFeature();
>>>>> rootElementName = eContainmentFeature.getName();
>>>>> rootElementNamespace =
>>>>> ExtendedMetaData.INSTANCE.getNamespace(eContainmentFeature);
>>>> You can look at documentRoot.getXMLNSPrefixMap(). It will have
>>>> mappings for all the xmlns declarations in the root element.
>>>>> }
>>>>> return rootElementNamespace;
>>>>> }
>>>>> }
>>>>> return null;
>>>>> .
>>>>> .
>>>>>
>>>>>
>>>>> Regards,
>>>>> Joachim
>>>>>
>>>
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: namespaceURI retrieval [message #421961 is a reply to message #421924] Tue, 19 August 2008 11:54 Go to previous messageGo to next message
J. Rietz is currently offline J. RietzFriend
Messages: 40
Registered: July 2009
Member
Ed,
Thanks for your support.

I was actually doing the same as the XMLContentHandlerImpl for my own
code.
But as the XMLContentHandlerImpl.createXMLResource() it creates a
specialized XML resource for consuming just the root elements (i.e.
doesn't parse whole doc) and throws exception when done, I never get to
the functions you mentioned in XMLHandler...and hereby the map is empty...
However, if continue parsing whole doc, the map is there.

So, I guess I don't have much choice than to parse whole doc?
Btw, which is the easiest way to do this?
Or is there other way than documentRoot.getXMLNSPrefixMap() if parsing
only root element?


/Joachim

Ed Merks wrote:

> Joachim,

> That's code which already exists in XMLHandler and which should be
> kicking in during the processing of your document. You'll want to see a
> breakpoint to see why it's not going there...


> Joachim Rietz wrote:
>> Hi again,
>>
>> Ehh, I'm not sure if I missed something obvious here, but I really
>> don't know what to do with the code you provided below...
>> Shall I add it in my code, where? Or how shall I use it?
>>
>> /Joachim
>>
>> Ed Merks wrote:
>>
>>> Joachim,
>>
>>> I'd expect this XMLHandler logic to kick in and do the trick:
>>
>>> | *public **void *endDocument()
>>> {
>>> *if *(deferredExtent != *null*)
>>> {
>>> extent.addAll(deferredExtent);
>>> }
>>
>>> // Pretend there is an xmlns="" because we really need to ensure
>> that the null prefix
>>> // isn't used to denote something other than the null namespace.
>>> //
>>> *if *(usedNullNamespacePackage)
>>> {
>>> helper.addPrefix("", "");
>>> }
>>> helper.recordPrefixToURIMapping();
>>> helper.popContext();
>>> handleForwardReferences(*true*);
>>
>>> *if *(disableNotify) {
>>> *for *(Iterator<?> i =
>> EcoreUtil.getAllContents(xmlResource.getContents(), *false*);
>> i.hasNext(); )
>>> {
>>> EObject eObject = (EObject)i.next();
>>> eObject.eSetDeliver(*true*);
>>> }
>>> }
>>
>>> *if *(extendedMetaData != *null*)
>>> {
>>> *if *(extent.size() == 1)
>>> {
>>> EObject root = extent.get(0);
>>> recordNamespacesSchemaLocations(root); }
>>
>>> *if *(DEBUG_DEMANDED_PACKAGES)
>>> {
>>> // EATM temporary for debug purposes only.
>>> //
>>> Collection<EPackage> demandedPackages =
>> EcoreUtil.copyAll(extendedMetaData.demandedPackages());
>>> *for *(EPackage ePackage : demandedPackages)
>>> {
>>> ePackage.setName(ePackage.getNsURI());
>>> }
>>> extent.addAll(demandedPackages);
>>> }
>>> }
>>> }
>>
>>> *protected *EMap<String, String>
>> recordNamespacesSchemaLocations(EObject root)
>>> {
>>> EClass eClass = root.eClass();
>>> EReference xmlnsPrefixMapFeature =
>> extendedMetaData.getXMLNSPrefixMapFeature(eClass);
>>> EMap<String, String> xmlnsPrefixMap = *null*;
>>> *if *(xmlnsPrefixMapFeature != *null*)
>>> {
>>> @SuppressWarnings("unchecked") EMap<String, String>
>> newXMLNSPrefixMap = (EMap<String,
>> String>)root.eGet(xmlnsPrefixMapFeature);
>>> xmlnsPrefixMap = newXMLNSPrefixMap;
>>> xmlnsPrefixMap.putAll(helper.getPrefixToNamespaceMap());
>>> }
>>
>>> *if *(urisToLocations != *null*)
>>> {
>>> EReference xsiSchemaLocationMapFeature =
>> extendedMetaData.getXSISchemaLocationMapFeature(eClass);
>>> *if *(xsiSchemaLocationMapFeature != *null*)
>>> {
>>> @SuppressWarnings("unchecked") EMap<String, String>
>> newXSISchemaLocationMap = (EMap<String,
>> String>)root.eGet(xsiSchemaLocationMapFeature);
>>> EMap<String, String> xsiSchemaLocationMap =
>> newXSISchemaLocationMap;
>>> *for *(Map.Entry<String, URI> entry :
>>> urisToLocations.entrySet())
>>> {
>>> xsiSchemaLocationMap.put(entry.getKey(),
>> entry.getValue().toString());
>>> }
>>> }
>>> }
>>> *return *xmlnsPrefixMap;
>>> }|
>>
>>
>>> Joachim Rietz wrote:
>>>> Ed, I've tried the documentRoot.getXMLNSPrefixMap(), but it returns
>>>> an empty map...
>>>> Are there some stuff to do to get this working properly?
>>>>
>>>> /Joachim
>>>>
>>>> Ed Merks wrote:
>>>>
>>>>> Joachim,
>>>>
>>>>> Comments below.
>>>>
>>>>
>>>>> Joachim Rietz wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I have code for retrieval of namespaceURI of a resource (see code
>>>>>> snippet below).
>>>>>> This code works fine, but now I need to find the other referenced
>>>>>> namespaceURI's in similar way.
>>>>>>
>>>>>> For instance if having below root:
>>>>>> <rbc:RbcAppl xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
>>>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>>>> xmlns:rbc="http://www.a.b/data/rbc/v8"
>>>>>> xmlns:rbc_bv="http://www.a.b/data/rbc_bv/v3"
>>>>>> xmi:id="_hFOnoCsXEd2CsoTXrynoRw" projectVersion="3">
>>>>>> code snippet below successfully gets the 'rbc' namespaceURI
>>>>>> "http://www.a.b/data/rbc/v8".
>>>>>>
>>>>>> But how do I manage to get the 'rbc_bv' namespaceURI??
>>>>>>
>>>>>> * * * * *
>>>>>> Code snippet:
>>>>>> .
>>>>>> .
>>>>>> XMLResource xmlResource = load(uri, inputStream, options, context);
>>>>> Are you parsing the whole document but you only need to get the
>>>>> information for the root element? EMF has support for content
>>>>> types now that handle this quite efficiently. You might want to
>>>>> look at how XMLContentHandlerImpl does this...
>>>>>> EList<EObject> contents = xmlResource.getContents();
>>>>>> if (!contents.isEmpty()) {
>>>>>> EObject eObject = contents.get(0);
>>>>>> if (eObject instanceof XMLTypeDocumentRoot) {
>>>>>> XMLTypeDocumentRoot documentRoot = (XMLTypeDocumentRoot)
>>>>>> eObject;
>>>>>> EList<EObject> rootContents = documentRoot.eContents();
>>>>>> String rootElementName = null;
>>>>>> String rootElementNamespace = null;
>>>>>> if (!rootContents.isEmpty()) {
>>>>>> EObject root = rootContents.get(0);
>>>>>> EReference eContainmentFeature =
>>>>>> root.eContainmentFeature();
>>>>>> rootElementName = eContainmentFeature.getName();
>>>>>> rootElementNamespace =
>>>>>> ExtendedMetaData.INSTANCE.getNamespace(eContainmentFeature);
>>>>> You can look at documentRoot.getXMLNSPrefixMap(). It will have
>>>>> mappings for all the xmlns declarations in the root element.
>>>>>> }
>>>>>> return rootElementNamespace;
>>>>>> }
>>>>>> }
>>>>>> return null;
>>>>>> .
>>>>>> .
>>>>>>
>>>>>>
>>>>>> Regards,
>>>>>> Joachim
>>>>>>
>>>>
>>>>
>>
>>
Re: namespaceURI retrieval [message #421962 is a reply to message #421961] Tue, 19 August 2008 12:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Joachim,

Comments below.

Joachim Rietz wrote:
> Ed,
> Thanks for your support.
>
> I was actually doing the same as the XMLContentHandlerImpl for my own
> code. But as the XMLContentHandlerImpl.createXMLResource() it creates
> a specialized XML resource for consuming just the root elements (i.e.
> doesn't parse whole doc) and throws exception when done, I never get
> to the functions you mentioned in XMLHandler...and hereby the map is
> empty...
Oh, I don't really like that. I think I should fix that, even if it
doesn't break the standard use case for this. I could imagine
specialized uses where the content type is determined by the presence of
several different namespaces on the root element...
> However, if continue parsing whole doc, the map is there.
>
> So, I guess I don't have much choice than to parse whole doc?
It should be possible to pop the stacks and force calls to endDocument
before throwing the exception but I'd need to look closely as some of
the cases to ensure that the right set of prefixes are recorded; there
might need to be calls to end element. If you open a bugzilla, I'll
investigate and try to come up with a solution you can reuse.
> Btw, which is the easiest way to do this?
> Or is there other way than documentRoot.getXMLNSPrefixMap() if parsing
> only root element?
The SAX callbacks do tell you about the prefixes...
>
>
> /Joachim
>
> Ed Merks wrote:
>
>> Joachim,
>
>> That's code which already exists in XMLHandler and which should be
>> kicking in during the processing of your document. You'll want to
>> see a breakpoint to see why it's not going there...
>
>
>> Joachim Rietz wrote:
>>> Hi again,
>>>
>>> Ehh, I'm not sure if I missed something obvious here, but I really
>>> don't know what to do with the code you provided below...
>>> Shall I add it in my code, where? Or how shall I use it?
>>>
>>> /Joachim
>>>
>>> Ed Merks wrote:
>>>
>>>> Joachim,
>>>
>>>> I'd expect this XMLHandler logic to kick in and do the trick:
>>>
>>>> | *public **void *endDocument()
>>>> {
>>>> *if *(deferredExtent != *null*)
>>>> {
>>>> extent.addAll(deferredExtent);
>>>> }
>>>
>>>> // Pretend there is an xmlns="" because we really need to
>>>> ensure
>>> that the null prefix
>>>> // isn't used to denote something other than the null
>>>> namespace.
>>>> //
>>>> *if *(usedNullNamespacePackage)
>>>> {
>>>> helper.addPrefix("", "");
>>>> }
>>>> helper.recordPrefixToURIMapping();
>>>> helper.popContext();
>>>> handleForwardReferences(*true*);
>>>
>>>> *if *(disableNotify) {
>>>> *for *(Iterator<?> i =
>>> EcoreUtil.getAllContents(xmlResource.getContents(), *false*);
>>> i.hasNext(); )
>>>> {
>>>> EObject eObject = (EObject)i.next();
>>>> eObject.eSetDeliver(*true*);
>>>> }
>>>> }
>>>
>>>> *if *(extendedMetaData != *null*)
>>>> {
>>>> *if *(extent.size() == 1)
>>>> {
>>>> EObject root = extent.get(0);
>>>> recordNamespacesSchemaLocations(root); }
>>>
>>>> *if *(DEBUG_DEMANDED_PACKAGES)
>>>> {
>>>> // EATM temporary for debug purposes only.
>>>> //
>>>> Collection<EPackage> demandedPackages =
>>> EcoreUtil.copyAll(extendedMetaData.demandedPackages());
>>>> *for *(EPackage ePackage : demandedPackages)
>>>> {
>>>> ePackage.setName(ePackage.getNsURI());
>>>> }
>>>> extent.addAll(demandedPackages);
>>>> }
>>>> }
>>>> }
>>>
>>>> *protected *EMap<String, String>
>>> recordNamespacesSchemaLocations(EObject root)
>>>> {
>>>> EClass eClass = root.eClass();
>>>> EReference xmlnsPrefixMapFeature =
>>> extendedMetaData.getXMLNSPrefixMapFeature(eClass);
>>>> EMap<String, String> xmlnsPrefixMap = *null*;
>>>> *if *(xmlnsPrefixMapFeature != *null*)
>>>> {
>>>> @SuppressWarnings("unchecked") EMap<String, String>
>>> newXMLNSPrefixMap = (EMap<String,
>>> String>)root.eGet(xmlnsPrefixMapFeature);
>>>> xmlnsPrefixMap = newXMLNSPrefixMap;
>>>> xmlnsPrefixMap.putAll(helper.getPrefixToNamespaceMap());
>>>> }
>>>
>>>> *if *(urisToLocations != *null*)
>>>> {
>>>> EReference xsiSchemaLocationMapFeature =
>>> extendedMetaData.getXSISchemaLocationMapFeature(eClass);
>>>> *if *(xsiSchemaLocationMapFeature != *null*)
>>>> {
>>>> @SuppressWarnings("unchecked") EMap<String, String>
>>> newXSISchemaLocationMap = (EMap<String,
>>> String>)root.eGet(xsiSchemaLocationMapFeature);
>>>> EMap<String, String> xsiSchemaLocationMap =
>>> newXSISchemaLocationMap;
>>>> *for *(Map.Entry<String, URI> entry :
>>>> urisToLocations.entrySet())
>>>> {
>>>> xsiSchemaLocationMap.put(entry.getKey(),
>>> entry.getValue().toString());
>>>> }
>>>> }
>>>> }
>>>> *return *xmlnsPrefixMap;
>>>> }|
>>>
>>>
>>>> Joachim Rietz wrote:
>>>>> Ed, I've tried the documentRoot.getXMLNSPrefixMap(), but it
>>>>> returns an empty map...
>>>>> Are there some stuff to do to get this working properly?
>>>>>
>>>>> /Joachim
>>>>>
>>>>> Ed Merks wrote:
>>>>>
>>>>>> Joachim,
>>>>>
>>>>>> Comments below.
>>>>>
>>>>>
>>>>>> Joachim Rietz wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I have code for retrieval of namespaceURI of a resource (see
>>>>>>> code snippet below).
>>>>>>> This code works fine, but now I need to find the other
>>>>>>> referenced namespaceURI's in similar way.
>>>>>>>
>>>>>>> For instance if having below root:
>>>>>>> <rbc:RbcAppl xmi:version="2.0"
>>>>>>> xmlns:xmi="http://www.omg.org/XMI"
>>>>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>>>>> xmlns:rbc="http://www.a.b/data/rbc/v8"
>>>>>>> xmlns:rbc_bv="http://www.a.b/data/rbc_bv/v3"
>>>>>>> xmi:id="_hFOnoCsXEd2CsoTXrynoRw" projectVersion="3">
>>>>>>> code snippet below successfully gets the 'rbc' namespaceURI
>>>>>>> "http://www.a.b/data/rbc/v8".
>>>>>>>
>>>>>>> But how do I manage to get the 'rbc_bv' namespaceURI??
>>>>>>>
>>>>>>> * * * * *
>>>>>>> Code snippet:
>>>>>>> .
>>>>>>> .
>>>>>>> XMLResource xmlResource = load(uri, inputStream, options, context);
>>>>>> Are you parsing the whole document but you only need to get the
>>>>>> information for the root element? EMF has support for content
>>>>>> types now that handle this quite efficiently. You might want to
>>>>>> look at how XMLContentHandlerImpl does this...
>>>>>>> EList<EObject> contents = xmlResource.getContents();
>>>>>>> if (!contents.isEmpty()) {
>>>>>>> EObject eObject = contents.get(0);
>>>>>>> if (eObject instanceof XMLTypeDocumentRoot) {
>>>>>>> XMLTypeDocumentRoot documentRoot = (XMLTypeDocumentRoot)
>>>>>>> eObject;
>>>>>>> EList<EObject> rootContents = documentRoot.eContents();
>>>>>>> String rootElementName = null;
>>>>>>> String rootElementNamespace = null;
>>>>>>> if (!rootContents.isEmpty()) {
>>>>>>> EObject root = rootContents.get(0);
>>>>>>> EReference eContainmentFeature =
>>>>>>> root.eContainmentFeature();
>>>>>>> rootElementName = eContainmentFeature.getName();
>>>>>>> rootElementNamespace =
>>>>>>> ExtendedMetaData.INSTANCE.getNamespace(eContainmentFeature);
>>>>>> You can look at documentRoot.getXMLNSPrefixMap(). It will have
>>>>>> mappings for all the xmlns declarations in the root element.
>>>>>>> }
>>>>>>> return rootElementNamespace;
>>>>>>> }
>>>>>>> }
>>>>>>> return null;
>>>>>>> .
>>>>>>> .
>>>>>>>
>>>>>>>
>>>>>>> Regards,
>>>>>>> Joachim
>>>>>>>
>>>>>
>>>>>
>>>
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: namespaceURI retrieval [message #422324 is a reply to message #421962] Fri, 29 August 2008 18:34 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040700090800090908080402
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Joachim,

Thanks for opening a bugzilla:
<https://bugs.eclipse.org/bugs/show_bug.cgi?id=245493>

https://bugs.eclipse.org/bugs/show_bug.cgi?id=245493

I've committed changes to improve this for 2.5.


Ed Merks wrote:
> Joachim,
>
> Comments below.
>
> Joachim Rietz wrote:
>> Ed,
>> Thanks for your support.
>>
>> I was actually doing the same as the XMLContentHandlerImpl for my own
>> code. But as the XMLContentHandlerImpl.createXMLResource() it creates
>> a specialized XML resource for consuming just the root elements (i.e.
>> doesn't parse whole doc) and throws exception when done, I never get
>> to the functions you mentioned in XMLHandler...and hereby the map is
>> empty...
> Oh, I don't really like that. I think I should fix that, even if it
> doesn't break the standard use case for this. I could imagine
> specialized uses where the content type is determined by the presence
> of several different namespaces on the root element...
>> However, if continue parsing whole doc, the map is there.
>>
>> So, I guess I don't have much choice than to parse whole doc?
> It should be possible to pop the stacks and force calls to endDocument
> before throwing the exception but I'd need to look closely as some of
> the cases to ensure that the right set of prefixes are recorded; there
> might need to be calls to end element. If you open a bugzilla, I'll
> investigate and try to come up with a solution you can reuse.
>> Btw, which is the easiest way to do this?
>> Or is there other way than documentRoot.getXMLNSPrefixMap() if
>> parsing only root element?
> The SAX callbacks do tell you about the prefixes...
>>
>>
>> /Joachim
>>
>> Ed Merks wrote:
>>
>>> Joachim,
>>
>>> That's code which already exists in XMLHandler and which should be
>>> kicking in during the processing of your document. You'll want to
>>> see a breakpoint to see why it's not going there...
>>
>>
>>> Joachim Rietz wrote:
>>>> Hi again,
>>>>
>>>> Ehh, I'm not sure if I missed something obvious here, but I really
>>>> don't know what to do with the code you provided below...
>>>> Shall I add it in my code, where? Or how shall I use it?
>>>>
>>>> /Joachim
>>>>
>>>> Ed Merks wrote:
>>>>
>>>>> Joachim,
>>>>
>>>>> I'd expect this XMLHandler logic to kick in and do the trick:
>>>>
>>>>> | *public **void *endDocument()
>>>>> {
>>>>> *if *(deferredExtent != *null*)
>>>>> {
>>>>> extent.addAll(deferredExtent);
>>>>> }
>>>>
>>>>> // Pretend there is an xmlns="" because we really need to
>>>>> ensure
>>>> that the null prefix
>>>>> // isn't used to denote something other than the null
>>>>> namespace.
>>>>> //
>>>>> *if *(usedNullNamespacePackage)
>>>>> {
>>>>> helper.addPrefix("", "");
>>>>> }
>>>>> helper.recordPrefixToURIMapping();
>>>>> helper.popContext();
>>>>> handleForwardReferences(*true*);
>>>>
>>>>> *if *(disableNotify) {
>>>>> *for *(Iterator<?> i =
>>>> EcoreUtil.getAllContents(xmlResource.getContents(), *false*);
>>>> i.hasNext(); )
>>>>> {
>>>>> EObject eObject = (EObject)i.next();
>>>>> eObject.eSetDeliver(*true*);
>>>>> }
>>>>> }
>>>>
>>>>> *if *(extendedMetaData != *null*)
>>>>> {
>>>>> *if *(extent.size() == 1)
>>>>> {
>>>>> EObject root = extent.get(0);
>>>>> recordNamespacesSchemaLocations(root); }
>>>>
>>>>> *if *(DEBUG_DEMANDED_PACKAGES)
>>>>> {
>>>>> // EATM temporary for debug purposes only.
>>>>> //
>>>>> Collection<EPackage> demandedPackages =
>>>> EcoreUtil.copyAll(extendedMetaData.demandedPackages());
>>>>> *for *(EPackage ePackage : demandedPackages)
>>>>> {
>>>>> ePackage.setName(ePackage.getNsURI());
>>>>> }
>>>>> extent.addAll(demandedPackages);
>>>>> }
>>>>> }
>>>>> }
>>>>
>>>>> *protected *EMap<String, String>
>>>> recordNamespacesSchemaLocations(EObject root)
>>>>> {
>>>>> EClass eClass = root.eClass();
>>>>> EReference xmlnsPrefixMapFeature =
>>>> extendedMetaData.getXMLNSPrefixMapFeature(eClass);
>>>>> EMap<String, String> xmlnsPrefixMap = *null*;
>>>>> *if *(xmlnsPrefixMapFeature != *null*)
>>>>> {
>>>>> @SuppressWarnings("unchecked") EMap<String, String>
>>>> newXMLNSPrefixMap = (EMap<String,
>>>> String>)root.eGet(xmlnsPrefixMapFeature);
>>>>> xmlnsPrefixMap = newXMLNSPrefixMap;
>>>>> xmlnsPrefixMap.putAll(helper.getPrefixToNamespaceMap());
>>>>> }
>>>>
>>>>> *if *(urisToLocations != *null*)
>>>>> {
>>>>> EReference xsiSchemaLocationMapFeature =
>>>> extendedMetaData.getXSISchemaLocationMapFeature(eClass);
>>>>> *if *(xsiSchemaLocationMapFeature != *null*)
>>>>> {
>>>>> @SuppressWarnings("unchecked") EMap<String, String>
>>>> newXSISchemaLocationMap = (EMap<String,
>>>> String>)root.eGet(xsiSchemaLocationMapFeature);
>>>>> EMap<String, String> xsiSchemaLocationMap =
>>>> newXSISchemaLocationMap;
>>>>> *for *(Map.Entry<String, URI> entry :
>>>>> urisToLocations.entrySet())
>>>>> {
>>>>> xsiSchemaLocationMap.put(entry.getKey(),
>>>> entry.getValue().toString());
>>>>> }
>>>>> }
>>>>> }
>>>>> *return *xmlnsPrefixMap;
>>>>> }|
>>>>
>>>>
>>>>> Joachim Rietz wrote:
>>>>>> Ed, I've tried the documentRoot.getXMLNSPrefixMap(), but it
>>>>>> returns an empty map...
>>>>>> Are there some stuff to do to get this working properly?
>>>>>>
>>>>>> /Joachim
>>>>>>
>>>>>> Ed Merks wrote:
>>>>>>
>>>>>>> Joachim,
>>>>>>
>>>>>>> Comments below.
>>>>>>
>>>>>>
>>>>>>> Joachim Rietz wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I have code for retrieval of namespaceURI of a resource (see
>>>>>>>> code snippet below).
>>>>>>>> This code works fine, but now I need to find the other
>>>>>>>> referenced namespaceURI's in similar way.
>>>>>>>>
>>>>>>>> For instance if having below root:
>>>>>>>> <rbc:RbcAppl xmi:version="2.0"
>>>>>>>> xmlns:xmi="http://www.omg.org/XMI"
>>>>>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>>>>>> xmlns:rbc="http://www.a.b/data/rbc/v8"
>>>>>>>> xmlns:rbc_bv="http://www.a.b/data/rbc_bv/v3"
>>>>>>>> xmi:id="_hFOnoCsXEd2CsoTXrynoRw" projectVersion="3">
>>>>>>>> code snippet below successfully gets the 'rbc' namespaceURI
>>>>>>>> "http://www.a.b/data/rbc/v8".
>>>>>>>>
>>>>>>>> But how do I manage to get the 'rbc_bv' namespaceURI??
>>>>>>>>
>>>>>>>> * * * * *
>>>>>>>> Code snippet:
>>>>>>>> .
>>>>>>>> .
>>>>>>>> XMLResource xmlResource = load(uri, inputStream, options,
>>>>>>>> context);
>>>>>>> Are you parsing the whole document but you only need to get the
>>>>>>> information for the root element? EMF has support for content
>>>>>>> types now that handle this quite efficiently. You might want to
>>>>>>> look at how XMLContentHandlerImpl does this...
>>>>>>>> EList<EObject> contents = xmlResource.getContents();
>>>>>>>> if (!contents.isEmpty()) {
>>>>>>>> EObject eObject = contents.get(0);
>>>>>>>> if (eObject instanceof XMLTypeDocumentRoot) {
>>>>>>>> XMLTypeDocumentRoot documentRoot = (XMLTypeDocumentRoot)
>>>>>>>> eObject;
>>>>>>>> EList<EObject> rootContents = documentRoot.eContents();
>>>>>>>> String rootElementName = null;
>>>>>>>> String rootElementNamespace = null;
>>>>>>>> if (!rootContents.isEmpty()) {
>>>>>>>> EObject root = rootContents.get(0);
>>>>>>>> EReference eContainmentFeature =
>>>>>>>> root.eContainmentFeature();
>>>>>>>> rootElementName = eContainmentFeature.getName();
>>>>>>>> rootElementNamespace =
>>>>>>>> ExtendedMetaData.INSTANCE.getNamespace(eContainmentFeature);
>>>>>>> You can look at documentRoot.getXMLNSPrefixMap(). It will have
>>>>>>> mappings for all the xmlns declarations in the root element.
>>>>>>>> }
>>>>>>>> return rootElementNamespace;
>>>>>>>> }
>>>>>>>> }
>>>>>>>> return null;
>>>>>>>> .
>>>>>>>> .
>>>>>>>>
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>> Joachim
>>>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>
>>

--------------040700090800090908080402
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Joachim,<br>
<br>
Thanks for opening a bugzilla:<a
href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=245493"><br>
</a>
<blockquote><a
href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=245493">https://bugs.eclipse.org/bugs/show_bug.cgi?id=245493</a><br>
</blockquote>
I've committed changes to improve this for 2.5.<br>
<br>
<br>
Ed Merks wrote:
<blockquote cite="mid:g8edfi$5d3$1@build.eclipse.org" type="cite">Joachim,
<br>
<br>
Comments below.
<br>
<br>
Joachim Rietz wrote:
<br>
<blockquote type="cite">Ed,
<br>
Thanks for your support.
<br>
<br>
I was actually doing the same as the XMLContentHandlerImpl for my own
code. But as the XMLContentHandlerImpl.createXMLResource() it creates a
specialized XML resource for consuming just the root elements (i.e.
doesn't parse whole doc) and throws exception when done, I never get to
the functions you mentioned in XMLHandler...and hereby the map is
empty...
<br>
</blockquote>
Oh, I don't really like that.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Question on using CDO to implement distributes telemetry capability.
Next Topic:Generating methods for multiple constraints
Goto Forum:
  


Current Time: Fri Apr 26 23:22:03 GMT 2024

Powered by FUDForum. Page generated in 0.04366 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top