Author |
Message
|
JosephGramig |
Posted: Fri Mar 18, 2016 8:41 am Post subject: For Namespace declarations on a specific tag in a JCN |
|
|
 Grand Master
Joined: 09 Feb 2006 Posts: 1244 Location: Gold Coast of Florida, USA
|
In this ESQL Example 1, I see they are creating a namespace declaration on a specific tag.
I need to do this to meet an IRS ACA spec.
I need to add a bunch of namespace declarations on the Envelope tag long before they are used. The parser puts them where they are first referenced.
What is the equivalent in Java?
I'm trying to get something like:
<soapenv:Envelope xmlns:soapenv="http...."
xmlns:NS1="http...1"
xmlns:NS2="http...2"
xmlns:NS3="http...3"
xmlns:NS4="http...4"
...
where the first reference of NS1 (or the others) is several more tags deep. |
|
Back to top |
|
 |
Gralgrathor |
Posted: Fri Mar 18, 2016 9:02 am Post subject: |
|
|
Master
Joined: 23 Jul 2009 Posts: 297
|
I think it would be something like this:
Code: |
String ns1 = "http://name/space/1";
// provided soapEnvelope points to the envelope element
MbElement ns1Decl = soapEnvelope.createElementAsLastChild(MbXMLNSC.NAMESPACE_DECLARATION, "ns1", ns1); |
and don't forget:
Code: |
someElement.setNamespace(ns1); |
to put the actual elements in their proper namespace. _________________ A measure of wheat for a penny, and three measures of barley for a penny; and see thou hurt not the oil and the wine. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Mar 18, 2016 9:08 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Gralgrathor wrote: |
I think it would be something like this:
Code: |
String ns1 = "http://name/space/1";
// provided soapEnvelope points to the envelope element
MbElement ns1Decl = soapEnvelope.createElementAsLastChild(MbXMLNSC.NAMESPACE_DECLARATION, "ns1", ns1); |
|
Yeah, I have some old code that is
Code: |
element.createElementAsFirstChild(MbXMLNSC.NAMESPACE_DECLARATION, "xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
|
obviously, first or last child doesn't make a huge difference. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
timber |
Posted: Fri Mar 18, 2016 9:11 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
If you're writing Java in a JavaCompute node then I strongly recommend that you use the JAXB option ( it's one of the options when you first configure the JCN).
Using JAXB, your Java code deals with Java objects that were generated from the XML Schema. Namespaces are automatically assigned where they are required. As a bonus, you get code assist ( ctrl-space ) to auto-complete the fields in your Java code.
All in all, it makes Java almost as nice to use as ESQL  |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Mar 18, 2016 9:18 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
timber wrote: |
If you're writing Java in a JavaCompute node then I strongly recommend that you use the JAXB option ( it's one of the options when you first configure the JCN).
Using JAXB, your Java code deals with Java objects that were generated from the XML Schema. Namespaces are automatically assigned where they are required. As a bonus, you get code assist ( ctrl-space ) to auto-complete the fields in your Java code.
All in all, it makes Java almost as nice to use as ESQL  |
JAXB may or may not allow for the necessary customization of the message tree to include weird and unnatural business requirements... _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
timber |
Posted: Fri Mar 18, 2016 9:56 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
True - it can only read and write message trees that conform to an XML Schema, so it's not a universal solution. But still pretty useful for the cases where it works, in my opinion. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Mar 18, 2016 10:04 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
|
Back to top |
|
 |
JosephGramig |
Posted: Tue Mar 22, 2016 5:16 am Post subject: |
|
|
 Grand Master
Joined: 09 Feb 2006 Posts: 1244 Location: Gold Coast of Florida, USA
|
This is what did work:
Code: |
private static String ACA_BH = "urn:us:gov:treasury:irs:msg:acabusinessheader";
...
MbElement outXMLNSC = outMessage.getRootElement().getLastChild();
MbElement outEnvelope = outXMLNSC.getFirstElementByPath("Envelope");
MbElement outBody = outEnvelope.getFirstElementByPath("Body");
MbElement outNS1attr = outBody.createElementBefore(MbElement.TYPE_NAME_VALUE, "xmlns:NS1", ACA_BH);
outNS1attr.setSpecificType(MbXMLNSC.NAMESPACE_DECLARATION);
|
|
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Mar 22, 2016 5:32 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
JosephGramig wrote: |
This is what did work:
Code: |
private static String ACA_BH = "urn:us:gov:treasury:irs:msg:acabusinessheader";
...
MbElement outXMLNSC = outMessage.getRootElement().getLastChild();
MbElement outEnvelope = outXMLNSC.getFirstElementByPath("Envelope");
MbElement outBody = outEnvelope.getFirstElementByPath("Body");
MbElement outNS1attr = outBody.createElementBefore(MbElement.TYPE_NAME_VALUE, "xmlns:NS1", ACA_BH);
outNS1attr.setSpecificType(MbXMLNSC.NAMESPACE_DECLARATION);
|
|
That's what I remember too... Before Body or First Child of Envelope makes really no distinction... unless you have to have the namespace declarations in a specific order...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
JosephGramig |
Posted: Tue Mar 22, 2016 9:06 am Post subject: |
|
|
 Grand Master
Joined: 09 Feb 2006 Posts: 1244 Location: Gold Coast of Florida, USA
|
Yes, the IRS BatShitCrazy ACA folks need a specific order. |
|
Back to top |
|
 |
timber |
Posted: Tue Mar 22, 2016 9:30 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Namespace declarations can appear in any order you like. Can you give an example of a valid XML document that the IRS application rejects? |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Mar 22, 2016 9:33 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
timber wrote: |
Namespace declarations can appear in any order you like. |
Assuming you're using a compliant XML parser to validate the document... _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
timber |
Posted: Tue Mar 22, 2016 12:26 pm Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
If the IRS is not using a compliant XML parser then somebody should get a rocket. It's still a possibility, and I knew that when I posted my question. But other possibilities also still exist becauseXML can be confusing and the receiving application can't speak up and defend itself. |
|
Back to top |
|
 |
|