Author |
Message
|
acrm1029 |
Posted: Tue Jun 02, 2015 2:30 pm Post subject: How to get minOccurs from computeNode |
|
|
Newbie
Joined: 02 Jun 2015 Posts: 7
|
Hi! I am working on WMB V7 and need to validate the content of the mandatory fields. However, I can´t find a way to access from code the minOccurs property found in the XSD.
For example if I have the following request message:
<request>
<name>Andres</name>
<number></number>
</request>
Based on the next XSD:
Code: |
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema>
<xsd:element name="request" type="this:request"></xsd:element>
<xsd:complexType name="request">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" minOccurs="1"></xsd:element>
<xsd:element name="number" type="xsd:string" minOccurs="1"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema> |
How can I access the minOccurs property of every field from code to validate that the field's content is not empty so I can generate an exception message. I can't modify neither the WSDL nor the XSD using minLenght=1  |
|
Back to top |
|
 |
iibmate |
Posted: Tue Jun 02, 2015 5:22 pm Post subject: Re: How to get minOccurs from computeNode |
|
|
 Apprentice
Joined: 17 Mar 2015 Posts: 38 Location: Perth, WA
|
acrm1029 wrote: |
Hi! I am working on WMB V7 and need to validate the content of the mandatory fields. However, I can´t find a way to access from code the minOccurs property found in the XSD.
For example if I have the following request message:
<request>
<name>Andres</name>
<number></number>
</request>
Based on the next XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema>
<xsd:element name="request" type="this:request"></xsd:element>
<xsd:complexType name="request">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" minOccurs="1"></xsd:element>
<xsd:element name="number" type="xsd:string" minOccurs="1"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
How can I access the minOccurs property of every field from code to validate that the field's content is not empty so I can generate an exception message. I can't modify neither the WSDL nor the XSD using minLenght=1  |
Requirement looks strange to me.
Put content validation at input of your transaction so that message can be validated aganist message set for content only.
For value validation, using If condition we can check if field value is blank or not. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Jun 03, 2015 4:25 am Post subject: Re: How to get minOccurs from computeNode |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
acrm1029 wrote: |
Hi! I am working on WMB V7 and need to validate the content of the mandatory fields. |
So use the validation features of the WMB software. You've paid a lot of money for it.
acrm1029 wrote: |
How can I access the minOccurs property of every field from code to validate that the field's content is not empty so I can generate an exception message. |
The short answer to how you can access the property is you can't - my comment above applies. You can determine which field is missing (for the purposes of error reporting) by looking at the Exception tree WMB generates in this circumstance.
The same is true for the content. If there's a requirement for content, the XSD should reflect that with any of the restrictions an XSD allows.
acrm1029 wrote: |
I can't modify neither the WSDL nor the XSD using minLenght=1 |
Why not? If it's owned by a third party who are sending empty (but present) tags then that's potentially content (i.e. a null tag). If you consider an empty element an error condition, then the XSD should reflect that. You also need to explain why, given that you can't change the source XSD, you can't change the copy imported into WMB to include the restrictions you need.
But it's easy enough (if tedious and pointless) to check field contents in code. The problem of not being able to refer back to the XSD doesn't apply because there's nothing in the XSD to refer to; if there was, you wouldn't be having this problem. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
acrm1029 |
Posted: Wed Jun 03, 2015 8:06 am Post subject: Re: How to get minOccurs from computeNode |
|
|
Newbie
Joined: 02 Jun 2015 Posts: 7
|
Vitor wrote: |
acrm1029 wrote: |
Hi! I am working on WMB V7 and need to validate the content of the mandatory fields. |
So use the validation features of the WMB software. You've paid a lot of money for it.
acrm1029 wrote: |
How can I access the minOccurs property of every field from code to validate that the field's content is not empty so I can generate an exception message. |
The short answer to how you can access the property is you can't - my comment above applies. You can determine which field is missing (for the purposes of error reporting) by looking at the Exception tree WMB generates in this circumstance.
The same is true for the content. If there's a requirement for content, the XSD should reflect that with any of the restrictions an XSD allows.
acrm1029 wrote: |
I can't modify neither the WSDL nor the XSD using minLenght=1 |
Why not? If it's owned by a third party who are sending empty (but present) tags then that's potentially content (i.e. a null tag). If you consider an empty element an error condition, then the XSD should reflect that. You also need to explain why, given that you can't change the source XSD, you can't change the copy imported into WMB to include the restrictions you need.
But it's easy enough (if tedious and pointless) to check field contents in code. The problem of not being able to refer back to the XSD doesn't apply because there's nothing in the XSD to refer to; if there was, you wouldn't be having this problem. |
The thing is that I was hoping there was a way to access those properties from Java, XSLT or ESQL... Now answering you question, I am not able to update de XSD file because that service is actually working productively and we are receiving in some cases the empty content tags and the backend is having troubles. We tought the most efficient way of dealing with this was validating content on the WMB.
Even though it is very easy to validate a field's content, I was looking for a solution I could apply to the around 45 services I have to modify in order to fix this content validation problem. |
|
Back to top |
|
 |
ganesh |
Posted: Wed Jun 03, 2015 8:41 am Post subject: Re: How to get minOccurs from computeNode |
|
|
Master
Joined: 18 Jul 2010 Posts: 294
|
acrm1029 wrote: |
Even though it is very easy to validate a field's content, I was looking for a solution I could apply to the around 45 services I have to modify in order to fix this content validation problem. |
Your number element in xsd is defined as string and strings can be null, however you can check if the value for an field is null. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Jun 03, 2015 8:45 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Tell the XMLNSC parser to use native types (if not using SOAP).
Tell IIB to validate the message and content.
That's it. |
|
Back to top |
|
 |
acrm1029 |
Posted: Wed Jun 03, 2015 8:45 am Post subject: Re: How to get minOccurs from computeNode |
|
|
Newbie
Joined: 02 Jun 2015 Posts: 7
|
ganesh wrote: |
acrm1029 wrote: |
Even though it is very easy to validate a field's content, I was looking for a solution I could apply to the around 45 services I have to modify in order to fix this content validation problem. |
Your number element in xsd is defined as string and strings can be null, however you can check if the value for an field is null. |
The question in fact is how can I know if a field is mandatory? Based on that I would validate the content. Knowing the field's mandatory information is on the XSD wich I am trying to access from code in WMB |
|
Back to top |
|
 |
acrm1029 |
Posted: Wed Jun 03, 2015 8:47 am Post subject: |
|
|
Newbie
Joined: 02 Jun 2015 Posts: 7
|
mqjeff wrote: |
Tell the XMLNSC parser to use native types (if not using SOAP).
Tell IIB to validate the message and content.
That's it. |
How can I do that? Since I am using SOAP |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Jun 03, 2015 8:47 am Post subject: Re: How to get minOccurs from computeNode |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
acrm1029 wrote: |
ganesh wrote: |
acrm1029 wrote: |
Even though it is very easy to validate a field's content, I was looking for a solution I could apply to the around 45 services I have to modify in order to fix this content validation problem. |
Your number element in xsd is defined as string and strings can be null, however you can check if the value for an field is null. |
The question in fact is how can I know if a field is mandatory? Based on that I would validate the content. Knowing the field's mandatory information is on the XSD wich I am trying to access from code in WMB |
You don't need to know that the field is mandatory.
The XSD knows that.
The validation uses the XSD.
Really. Stop trying to code this yourself. |
|
Back to top |
|
 |
ganesh |
Posted: Wed Jun 03, 2015 8:55 am Post subject: Re: How to get minOccurs from computeNode |
|
|
Master
Joined: 18 Jul 2010 Posts: 294
|
acrm1029 wrote: |
The question in fact is how can I know if a field is mandatory? |
You have the xsd dont you? xsd should tell you whether a field is mandatory or optional and you have the xsd before starting to code so while coding check the xsd and code accordingly. |
|
Back to top |
|
 |
kimbert |
Posted: Thu Jun 04, 2015 1:11 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
I think the point has been missed here. The XML looks like this:
Code: |
<request>
<name>Andres</name>
<number></number>
</request> |
...and the OP wants to know how to value that <number> has a value.
The problem is that minOccurs is not even relevant to this problem. That will only check that the tag is present ( and it is ). The XSD needs to be changed so that the simple type of the 'number' element has a minLength facet.
But unfortunately the OP also said
Quote: |
I can't modify neither the WSDL nor the XSD using minLenght=1 |
So there is no good solution available. The obvious technical solution has been ruled out. The only alternative is to write some code in the message flow to validate that the number field is not empty.
My advice? Tell the architects ( or whoever claims that the XSD cannot be changed ) that this is impacting the project schedule. They can have a poor. unmaintainable solution or a good, maintainable one that requires changing the WSDLs and/or XSDs. _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
|