Author |
Message
|
lanny boy |
Posted: Wed Jul 28, 2004 5:34 am Post subject: Parsing XML Namespace |
|
|
Voyager
Joined: 24 Nov 2003 Posts: 79 Location: UK
|
Hi
I have imported an XML schema into the MRM and am trying to use it to validate a message as it comes in.
The messages which come in will have a namespace of Doc: before each element. Unfortunately I can only get this message to be parsed correctly if I remove the Doc: from before/after each element.
Is their somewhere where I can thell the MRM to expect the prefix?
I have tried to set #
xsiPrefix=Doc:
# in the XML Schema import file.
Lanny Boy |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jul 28, 2004 5:36 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
What version are you running? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
lanny boy |
Posted: Wed Jul 28, 2004 5:37 am Post subject: |
|
|
Voyager
Joined: 24 Nov 2003 Posts: 79 Location: UK
|
|
Back to top |
|
 |
JLRowe |
Posted: Wed Jul 28, 2004 6:30 am Post subject: |
|
|
 Yatiri
Joined: 25 May 2002 Posts: 664 Location: South East London
|
2.1 does not support XML namespaces, v5 does. |
|
Back to top |
|
 |
shanson |
Posted: Thu Jul 29, 2004 9:16 am Post subject: |
|
|
 Partisan
Joined: 17 Oct 2003 Posts: 344 Location: IBM Hursley
|
This should still work. While it is correct to say that 2.1 does not support namespaces, it does allow you to parse XML instance documents that contains namespace prefixes. The 2.1 XML schema importer shipped with the product from CSD3 onwards will look at the namespace prefixes and fill in the XML wire format 'XML element name' property to include the prefix. So for element 'XYZ' with prefix 'abc' you will get XML element name of 'abc:XYZ' which will match the instance document when parsed.
For this to work you need to have added your XML wire format to the message set *before* you import the XML schema. |
|
Back to top |
|
 |
lanny boy |
Posted: Mon Aug 02, 2004 6:33 am Post subject: |
|
|
Voyager
Joined: 24 Nov 2003 Posts: 79 Location: UK
|
Hi shanson, thanks for your reply, however unfortunately I could not get this to work.
I created a new message set and added the XML layer. I then imported the schema into the set with the following line in the import file.
#
#
[NAMESPACEPREFIX]
#
http://www.w3.org/2001/XMLSchema abc
#
#
From reading your reply I would have (mistakenly?) expected to be able to successfully parse the following
<abc:Name>Smith</abc:Name>
The XML element name property, which I could not find although I assume this is the XML name field? did not pick up the value abc. I also tried to set it myself but this did not work either.
Have I missed something out?
Any further help would be greatfully received
Lanny boy |
|
Back to top |
|
 |
shanson |
Posted: Mon Aug 02, 2004 7:13 am Post subject: |
|
|
 Partisan
Joined: 17 Oct 2003 Posts: 344 Location: IBM Hursley
|
You don't need to specify the [NAMESPACEPREFIX] stanza, the namespace declarations in the XML schema file should contain all the information necessary for the importer. I think you had better append your schema file, so I can check it is ok.
Note that your example [NAMESPACEPREFIX] stanza looks incorrect - you seem to be giving the XML schema-for-schema namespace a prefix 'abc'. This would usually be 'xs' or 'xsd'. It is your own target namespace that should be prefixed 'abc'.
Have you read the 2.1 CSD3 (or higher) 'Working with Messages' book? It has a whole section on the schema importer, that explains how the XML Name property gets set? |
|
Back to top |
|
 |
lanny boy |
Posted: Mon Aug 02, 2004 7:57 am Post subject: |
|
|
Voyager
Joined: 24 Nov 2003 Posts: 79 Location: UK
|
I've had another go with a little more success!! However I'm not sure if i fully understand why it works or what else I can actually achieve...
I removed the NAMESPACEPREFIX stanza and set the xsiPrefix=abc (I have included the full file at the end of the post). When I reimported this in it still did not work. But when i changed the Element name message property to abc:Document it parsed my message. I thought this would be set to abc upon import?
Another question i have is that we will not know when we receive our document what the namespace will be! It could be xyz: or abc: or even not contain any namespace. Is it possible to use wildcard characters for the prefix or remove them completely!
I have read the 'Working with Messages' book but a lot of it seems a little ambiguos (possibly due to my lack of XML knowledge!).
# Parameters file for mqsi v2.1
#
# Name of Message set to import/create
#
MessageSet=SWIFTML3
#
# Name of MRM Database
#
MRM_DB=WMQIMRDB
#
# MRM Database USerID
#
DB_User=db2admin
#
# MRM Database password
#
DB_PW=db2admin
#
# Name of top leve XML root element
#
RootElement=Document
#
xsiPrefix=Doc
#
SchemaLoc="SWIFT.IF.IA$IFDS.001.001.01.XSD"
#
#DefNameSpace=xmlns:xs="http://www.w3.org/2001/XMLSchema"
#
# List of Schema files
#
#
[FILELIST]
#
# Name of XML Schema file
#
SWIFT.IF.IA$IFDS.001.001.01.XSD
#
#
[FILELOCATION]
#
# Where to find the xsd file
#
c:\
# |
|
Back to top |
|
 |
shanson |
Posted: Mon Aug 02, 2004 11:47 pm Post subject: |
|
|
 Partisan
Joined: 17 Oct 2003 Posts: 344 Location: IBM Hursley
|
1) #xsiPrefix is the prefix for the XML Schema Instance namespace, not your target namespace, and it should normally be set to "xsi".
2) You are setting the #DefNameSpace option. I don't think you need to do this. Moreover you are setting it to the XML Schema for Schema Namespace, which is not what I would expect. Try removing this from the options file altogether.
Please can you append your schema file (the .xsd file). Specifically I need to see the <xsd:schema ...> element in order to see what your target namespace is and what prefixes are being declared.
To answer your question on variable prefixes, this is not supported. Remember that 2.1 does not properly support namespaces, and works by setting the XML name of an element to "prefix:name". So the XML instance document MUST be exactly that.
You say you are new to XML. If you have not first read the XML Namespaces spec and then read the XML Schema primer, I strongly recommend that you do. Namespaces are a significant and non-trivial extension to XML, and heavily used by Schema.
Namespaces: http://www.w3.org/TR/REC-xml-names/
Schema Primer: http://www.w3.org/TR/xmlschema-0/ |
|
Back to top |
|
 |
lanny boy |
Posted: Tue Aug 03, 2004 1:03 am Post subject: |
|
|
Voyager
Joined: 24 Nov 2003 Posts: 79 Location: UK
|
Thanks for your help shanson, it is very helpful.
1) It does not seem to matter what value i put in the xsiPrefix field, I have returned it to xsi (or should it be xs! (see schema)).
2)the #DefNameSpace was never actually included as it was commented out on the import file I was using.
I have included the info you asked for from the xsd file(all the prefixes are xs: not xsd:) The schema is very large so i have just included the beginning.
You mention that namespaces must be declared in the schema
Quote: |
in order to see what your target namespace is and what prefixes are being declared.
|
. This suggests that (as far as MQSI is concerned anyway) each prefix must be declared in the schema, ie abc:, xyz: etc?
So, as far as the import script is concerned the incoming prefixes on xml messages have no place, instead the schema is the place to declare them.
I am coming to the conclusion that V2.1 does not offer me the functionality to offer me a solution to the problem I have, and am coming up with some alternatives. A long shot I know but installing V5 over a 2.1 broker would offer me no new XML functionality!? (Unfortunately our V5 upgrade schedule does not allow us to use the product on this project).
Any answers / pointers would be helpful
(BTW thanks for the links)
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:abcde:xsd:abcde.if.ia$ifds.efg.019.01"
xmlns:xsd="urn:abcde:xsd:abcde.if.ia$ifds.efg.019.01"
elementFormDefault="qualified">
<xs:element name="Document" type="Document"/>
<xs:complexType name="Document">
<xs:sequence>
<xs:element name="ifds.efg.019.01" type="ifds.efg.019.01"/>
</xs:sequence>
</xs:complexType> |
|
Back to top |
|
 |
shanson |
Posted: Tue Aug 03, 2004 2:44 am Post subject: |
|
|
 Partisan
Joined: 17 Oct 2003 Posts: 344 Location: IBM Hursley
|
Things are becoming clearer. What a poor use of namespace URIs and prefixes. The targetNamespace is not a URI at all (which is allowed but not best practice). And its associated prefix is "xsd" which is normally one of the choices of prefix for XML Schema for Schema namespace. Confusing to say the least.
Btw the XML Schema Instance namespace is not the same as the XML Schema for Schema namespace. The former uses prefix "xsi", the latter in your case is using "xs".
If you import this, then you should find that your XML wire format "XML name" properties are prefixed with "xsd" (we've tried this, it works). You should be seeing "xsd:Document" and "xsd:ifds.efg.019.01". That means your XML instance documents MUST use "xsd" as the prefix (because you are at V2.1 and not V5).
Each XML schema has a single target namespace defined by a URI. The schema defines a prefix as a shorthand for the target namespace URI, for use within the schema document itself. Each XML instance document conforming to the schema is free to use its own prefix for the target namespace URI; typically they use the same prefix as the schema, but they don't have to. The scope of a prefix is limited to the XML document it is declared in, and has no meaning outside.
If your apps are using different prefixes for the target namespace, which it sounds like they are, then if there are just a few apps you could create a different message set for use by each application; each message set would specify a different prefix. If you are using MQRFH2 headers then each app must specify the correct message set in the MQRFH2, otherwise you will to contruct your message flow to cater for this (either have a different input node for each app which specifies the correct message set, or initially parse the message in the BLOB or XML domains and peek at the prefix before routing to ResetContentDescriptor nodes that will reparse with the correct message set).
You can't install just a V5 broker; you have to first install the V5 toolkit and config manager. So even if your timescales permitted, upgrading your broker alone to V5 is not an option.
Here is the options file we used:
#
# Parameters file for MQSI V2.1 XML Schema importer
[HEADER]
#
# Name of the message set to import the message into
#
MessageSet=SWIFTML3
#
# Name of the MRM database to import into
#
MRM_DB=MQSIMRDB
#
# MRM Database User id - can be overridden on the command line
#
DB_User=db2admin
#
# MRM Database Password - can be overridden on the command line
#
DB_PW=db2admin
#
# Name of the top level element in the MRM message
#
RootElement=Document
#
[FILELIST]
test.xsd
#
# Name of the XML Schema file
#
[NAMESPACEPREFIX]
# |
|
Back to top |
|
 |
lanny boy |
Posted: Tue Aug 03, 2004 5:31 am Post subject: |
|
|
Voyager
Joined: 24 Nov 2003 Posts: 79 Location: UK
|
Thanks for your help, I have now reached a stage where I can parse any incoming message (as long as I have prior knowledge of the prefix being sent and created the corresponding message set).
The problem I have is that all the people using the schema and the schema owners itself are third party, so there are potentially lots of prefixes / message sets to cater for!! Although obviously we will try to impose the same ones on each party!
As a final question what performance overhead is there to having a lot of message sets in a broker?
Lanny boy. |
|
Back to top |
|
 |
shanson |
Posted: Tue Aug 03, 2004 6:21 am Post subject: |
|
|
 Partisan
Joined: 17 Oct 2003 Posts: 344 Location: IBM Hursley
|
There is a memory overhead, as the dictionary for each message set will get loaded as and when it is needed. But that should be all. |
|
Back to top |
|
 |
|