View previous topic :: View next topic |
Author |
Message |
misi01 Advanced
Joined: 02 Dec 2002 Posts: 616 Topics: 171 Location: Stockholm, Sweden
|
Posted: Wed Sep 16, 2015 1:42 am Post subject: COBOL and XML generate and multiple namespaces |
|
|
I'll start off by saying I have a strong suspicion that I want to do can't be done. Here's my code
Code: |
01 header_h.
05 filler pic x(35) value
'xmlns:h=http://www.w3.org/TR/html4/'.
05 filler pic x(44) value
'xmlns:f="http://www.w3schools.com/furniture"'.
01 tableh.
10 tr.
15 td pic x(10) value 'Apples'.
15 h_td pic x(10) value 'Bananas'.
05 f_tablex.
10 f_name pic x(20) value
'African Coffee Table'.
10 f_width pic xx value '80'.
10 f_length pic xxx value '120'.
|
(Basically, I've "translated" this from an example at
http://www.w3schools.com/xml/xml_namespaces.asp)
My generate code is
Code: |
XML GENERATE AA-XML-OUT-DATA FROM tableh
COUNT IN AA-XML-LANGD
NAMESPACE header_h
namespace-prefix is "H"
|
but the generate is always giving XML-code 416 (which says The XML namespace identifier contained invalid XML characters without my being able to find anywhere that indicate WHAT characters are (in)valid).
If I comment out the second filler in header_h, no problems.
Is this simply a case of "this isn't supported" or am I doing something wrong?
(BTW, we're running Cobol 4.2) _________________ Michael |
|
Back to top |
|
|
William Collins Supermod
Joined: 03 Jun 2012 Posts: 437 Topics: 0
|
Posted: Wed Sep 16, 2015 3:33 am Post subject: |
|
|
Counting bytes (not manually) indicates your two FILLER fields run into each other, which would make it one big long thing, and which would make it (the namespace) contain a ":", which I'd go for as the invalid character (there must be a list of valid symbols for a URL, somewhere). |
|
Back to top |
|
|
misi01 Advanced
Joined: 02 Dec 2002 Posts: 616 Topics: 171 Location: Stockholm, Sweden
|
Posted: Wed Sep 16, 2015 4:32 am Post subject: |
|
|
Sorry William, my bad.
The code fails even when defined like this:-
Code: |
01 header_h.
05 filler pic x(35) value
'xmlns:h=http://www.w3.org/TR/html4/'.
05 filler pic x(45) value
' xmlns:f="http://www.w3schools.com/furniture"'.
|
_________________ Michael |
|
Back to top |
|
|
William Collins Supermod
Joined: 03 Jun 2012 Posts: 437 Topics: 0
|
Posted: Wed Sep 16, 2015 4:45 am Post subject: |
|
|
OK, let's see if we can confirm it is not the quotes. Comment the second FILLER, put quotes around the first URL. If that fails now, do the obvious.
Can you show the XML that is generated when you comment-out the second FILLER (either currently, or during the above)? |
|
Back to top |
|
|
William Collins Supermod
Joined: 03 Jun 2012 Posts: 437 Topics: 0
|
Posted: Wed Sep 16, 2015 5:27 am Post subject: |
|
|
I'm beginning to think your strong suspicion is correct. Sort of. I don't thing you can do it with one XML GENERATE. Unless the alternative of specifying by attributes would work, which I've not looked at.
Whether two GENERATEs, with the different NAMESPACE, will do what you want... |
|
Back to top |
|
|
misi01 Advanced
Joined: 02 Dec 2002 Posts: 616 Topics: 171 Location: Stockholm, Sweden
|
Posted: Wed Sep 16, 2015 6:04 am Post subject: |
|
|
Here are the results based on the following definition
Code: |
*
01 header_h.
05 filler pic x(35) value
'xmlns:h=http://www.w3.org/TR/html4/'.
* 05 filler pic x(45) value
* ' xmlns:f="http://www.w3schools.com/furniture"'.
|
The results are here (the leading *** is just so I can see where the string actually starts)
Quote: |
***<H:tableh xmlns:H="xmlns:h=http://www.w3.org/TR/html4/"><H:tr><H:td>Apples</
H:td><H:h_td>Bananas</H:h_td></H:tr><H:f_
tablex><H:f_name>African Coffee Table</H:f_name><H:f_width>80</H:f_width><H:f_l
ength>120</H:f_length></H:f_tablex></H:tableh>
|
I can't see any reason why 2 different generates wouldn't work (each with its own namespace).
All this started because a colleague needed to generate some XML with multiple namespaces. Theoretically, I could have suggested he do multiple generates, but it then turned out that the generated tags didn't all have the same prefix. Based on what he really wanted to, his cobol variables looked like these
Code: |
10 smap_Security.
15 smap_UASToken.
20 IPIdfr PIC X(11).
20 UASid PIC X(40).
10 ctx_User.
15 IPRef.
20 IPIdfr PIC X(11).
|
The trouble with the above is that for the first 10-level variable, he wants smap prepended, but not for IPIDFR or UASID. Based on that (as I understand), you can't simply remove the smap_ text and then generate using namespace-prefix since IPIDFR/UASID would also be prefixed with smap (not what he wants) _________________ Michael |
|
Back to top |
|
|
William Collins Supermod
Joined: 03 Jun 2012 Posts: 437 Topics: 0
|
Posted: Wed Sep 16, 2015 6:29 am Post subject: |
|
|
Ah. That isn't how the namespace works. Even in the w3schools example, it is going to pre-pend everything.
It would require a post-process of the generated XML I think.
It would leave the IPIdfr "unqualified", but that needn't be a problem (as long as a higher level is unique).
It may be that although your colleague doesn't want the prefix it isn't an actual problem either. I'm not sure if the qualification would be ignored by whatever consumes the xml if it is not used.
Whilst pasting up your example, I modified the header. I don't think you should have the xmlns stuff in the text, as the GENERATE is adding it anyway.
Confirm whether the prefix on the subordinate fields is a problem; post-process the generated XML to add the prefix where required (or remove where not). |
|
Back to top |
|
|
William Collins Supermod
Joined: 03 Jun 2012 Posts: 437 Topics: 0
|
Posted: Wed Sep 16, 2015 1:17 pm Post subject: |
|
|
After that I became confused about what the problem was. After all, the prefix is there in the definition.
So, is it a definition used by other programs?
If so, you can "nest" the copybook for the other programs, with a COPY ... REPLACING inside. And then in the XML program, just use the internal copy, with the REPLACING.
Code: |
10 :XMLPREFIX:SEURITY. |
In the main copybook, the REPLACING will be
Code: | ==:XMLPREFIX:== BY == == |
In the XML proigram
Code: | ==:XMLPREFIX:== BY ==SMAP_== |
|
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12357 Topics: 75 Location: San Jose
|
Posted: Wed Sep 16, 2015 1:21 pm Post subject: |
|
|
William Collins wrote: | After that I became confused about what the problem was. After all, the prefix is there in the definition.
So, is it a definition used by other programs? |
I think OP wants to have a separate prefix for an array of Namespace fields.
For the first one he wanted to have :h=http:/.. and the second one has :F=http:/ .. so on.
Ideally I would Build the xml doc and then use inspect to change the prefixes but that is just me. _________________ Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
misi01 Advanced
Joined: 02 Dec 2002 Posts: 616 Topics: 171 Location: Stockholm, Sweden
|
Posted: Thu Sep 17, 2015 12:48 am Post subject: |
|
|
Kolusu.
That is what we ended up doing. In our example, we had to include a slew (sp?) of namespaces, so instead of trying to do the XML generate with the namespace argument, we simply included ALL the namespaces at the beginning of the XML data.
Since the actual tags were all supposed to be prefixed by ku: we defined the WS variables as ku_xxxxxx and then, after the generate, simply did an inspect changing all '_' to ':' which worked fine. _________________ Michael |
|
Back to top |
|
|
misi01 Advanced
Joined: 02 Dec 2002 Posts: 616 Topics: 171 Location: Stockholm, Sweden
|
Posted: Thu Sep 17, 2015 12:56 am Post subject: |
|
|
William. Your copy replacing idea is a great idea .... except for the fact that we use a Data dictionary to generate copybooks which means that all variables are prefixed with the same (say) :xx: (that's : x x : without the spaces).
So you can't generate some variables with a :xx: prefix and others without.
If we defined the copybook as I think you're suggesting, the copybook would be generated as
Code: |
10 :xx:Security.
15 :xx:UASToken.
20 :xx:IPIdfr PIC X(11).
20 :xx:UASid PIC X(40).
|
so we're back to the problem (in this case) of certain variables being prefixed by smap: and others not. _________________ Michael |
|
Back to top |
|
|
William Collins Supermod
Joined: 03 Jun 2012 Posts: 437 Topics: 0
|
Posted: Thu Sep 17, 2015 2:51 am Post subject: |
|
|
Michael, if you use the Post Reply button originally, or the Preview subsequently, there is a check-box underneath the input box which allows you to Disable Smilies in this post. I've edited your post to include that option, although there was a great deal of irony in the fierce-frustrated-looking Smilie which the x: produces. Whoops. There it is again.
The use of a Data Dictionary is not an impediment in itself. It should be possible to define an attribute for an "xml prefix", either with specific actual values, or readily "replaceable" values (or something else) depending on which fits best with the "style" of use of your Data Dictionary.
What can get in the way of that is the knowledge/resources/status of the Data Dictionary/DD Team.
I know this would have been possible 28 years ago with Datamanager, because we wanted to do something analagous, and talking it through with the admin guy it was possible and even simple, and once we'd got the idea, it was something open to other uses.
However, not all sites who use a Data Dictionary like to use it beyond the basics |
|
Back to top |
|
|
|
|