How to check an element's type against an XSD simple type
Friday, 11 March 2016 · 5 messages · last reply 12 Mar 2016
UG
Ulrike Schaper - SideStep Business Solutions GmbH11 Mar 2016 10:02 #
Hi everybody,
I'm trying to compose XML documents for SEPA transactions via BaseX. I would like to check certain data against the corresponding schema before putting them into the document, e.g. BIC identifiers.
In the xsd, there's a simpleType definition for BICs:
<xs:simpleType name="BICIdentifier">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}"/>
</xs:restriction>
</xs:simpleType>I hoped it would be as simple as
declare default element namespace "urn:iso:std:iso:20022:tech:xsd:pain.001.003.03";
let $node := <BIC>GEN0DEM1MPW</BIC>
return if(string($node) instance of BICIdentifier) then (true() (: process... :)) else (false() (: report error :))But, as I learned now, BaseX doesn't support import of schemas. Thus, I receive the error message "Unknown type: Q{urn:iso:std:iso:20022:tech:xsd:pain.001.003.03 }BICIdentifier".
Is there some workaround (other than rebuilding regular expressions from schema to xquery)?
Best regards,
Ulrike.
CG
Christian Grün11 Mar 2016 11:20 #
Hi Ulrike,
The Validation Module should help you here, in particular
validate:xsd-report [1]. It allows you to pass on file URIs or XML fragments as arguments.
All the best,
Christian
[1] http://docs.basex.org/wiki/Validation_ModuleQuoted text · Ulrike Schaper - SideStep Business Solutions GmbH · 56 lines
On Fri, Mar 11, 2016 at 10:02 AM, Ulrike Schaper - SideStep Business Solutions GmbH <U.Schaper at sidestep-solutions.de> wrote: > Hi everybody, > > > > I’m trying to compose XML documents for SEPA transactions via BaseX. > > I would like to check certain data against the corresponding schema before > putting them into the document, e.g. BIC identifiers. > > > > In the xsd, there’s a simpleType definition for BICs: > > <xs:simpleType name="BICIdentifier"> > > <xs:restriction base="xs:string"> > > <xs:pattern > value="[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}"/> > > </xs:restriction> > > </xs:simpleType> > > > > I hoped it would be as simple as > > > > declare default element namespace > "urn:iso:std:iso:20022:tech:xsd:pain.001.003.03"; > > let $node := <BIC>GEN0DEM1MPW</BIC> > > return if(string($node) instance of BICIdentifier) then (true() (: > process... :)) else (false() (: report error :)) > > > > But, as I learned now, BaseX doesn’t support import of schemas. Thus, I > receive the error message “Unknown type: > Q{urn:iso:std:iso:20022:tech:xsd:pain.001.003.03 }BICIdentifier”. > > > > Is there some workaround (other than rebuilding regular expressions from > schema to xquery)? > > > > Best regards, > > Ulrike.
CG
Christian Grün11 Mar 2016 11:23 #
PS: If it’s only about BIC validation, you can obviously use standard XQuery:
declare variable $BIC-PATTERN :=
'[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}';
let $node := <BIC>GEN0DEM1MPW</BIC>
return if(matches($node, $BIC-) then 'well done' else 'sigh'Quoted text · Christian Grün · 71 lines
On Fri, Mar 11, 2016 at 11:20 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Ulrike, > > The Validation Module should help you here, in particular > validate:xsd-report [1]. It allows you to pass on file URIs or XML > fragments as arguments. > > All the best, > Christian > > [1] http://docs.basex.org/wiki/Validation_Module > > > > On Fri, Mar 11, 2016 at 10:02 AM, Ulrike Schaper - SideStep Business > Solutions GmbH <U.Schaper at sidestep-solutions.de> wrote: >> Hi everybody, >> >> >> >> I’m trying to compose XML documents for SEPA transactions via BaseX. >> >> I would like to check certain data against the corresponding schema before >> putting them into the document, e.g. BIC identifiers. >> >> >> >> In the xsd, there’s a simpleType definition for BICs: >> >> <xs:simpleType name="BICIdentifier"> >> >> <xs:restriction base="xs:string"> >> >> <xs:pattern >> value="[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}"/> >> >> </xs:restriction> >> >> </xs:simpleType> >> >> >> >> I hoped it would be as simple as >> >> >> >> declare default element namespace >> "urn:iso:std:iso:20022:tech:xsd:pain.001.003.03"; >> >> let $node := <BIC>GEN0DEM1MPW</BIC> >> >> return if(string($node) instance of BICIdentifier) then (true() (: >> process... :)) else (false() (: report error :)) >> >> >> >> But, as I learned now, BaseX doesn’t support import of schemas. Thus, I >> receive the error message “Unknown type: >> Q{urn:iso:std:iso:20022:tech:xsd:pain.001.003.03 }BICIdentifier”. >> >> >> >> Is there some workaround (other than rebuilding regular expressions from >> schema to xquery)? >> >> >> >> Best regards, >> >> Ulrike.
CG
Christian Grün11 Mar 2016 11:28 #
Sorry, a last one: Here is the fixed version of the query:
declare variable $BIC-PATTERN :=
'^[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}$';
let $node := <BIC>GEN0DEM1MPW</BIC>
return if(matches($node, $BIC-PATTERN)) then 'well done' else 'sigh'Most importantly, you’ll have to wrap your regex pattern with ^ and $ in order to ensure that there are no other heading or trailing characters in the BIC string.
Quoted text · Christian Grün · 83 lines
On Fri, Mar 11, 2016 at 11:23 AM, Christian Grün <christian.gruen at gmail.com> wrote: > PS: If it’s only about BIC validation, you can obviously use standard XQuery: > > declare variable $BIC-PATTERN := > '[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}'; > let $node := <BIC>GEN0DEM1MPW</BIC> > return if(matches($node, $BIC-) then 'well done' else 'sigh' > > > > > On Fri, Mar 11, 2016 at 11:20 AM, Christian Grün > <christian.gruen at gmail.com> wrote: >> Hi Ulrike, >> >> The Validation Module should help you here, in particular >> validate:xsd-report [1]. It allows you to pass on file URIs or XML >> fragments as arguments. >> >> All the best, >> Christian >> >> [1] http://docs.basex.org/wiki/Validation_Module >> >> >> >> On Fri, Mar 11, 2016 at 10:02 AM, Ulrike Schaper - SideStep Business >> Solutions GmbH <U.Schaper at sidestep-solutions.de> wrote: >>> Hi everybody, >>> >>> >>> >>> I’m trying to compose XML documents for SEPA transactions via BaseX. >>> >>> I would like to check certain data against the corresponding schema before >>> putting them into the document, e.g. BIC identifiers. >>> >>> >>> >>> In the xsd, there’s a simpleType definition for BICs: >>> >>> <xs:simpleType name="BICIdentifier"> >>> >>> <xs:restriction base="xs:string"> >>> >>> <xs:pattern >>> value="[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}"/> >>> >>> </xs:restriction> >>> >>> </xs:simpleType> >>> >>> >>> >>> I hoped it would be as simple as >>> >>> >>> >>> declare default element namespace >>> "urn:iso:std:iso:20022:tech:xsd:pain.001.003.03"; >>> >>> let $node := <BIC>GEN0DEM1MPW</BIC> >>> >>> return if(string($node) instance of BICIdentifier) then (true() (: >>> process... :)) else (false() (: report error :)) >>> >>> >>> >>> But, as I learned now, BaseX doesn’t support import of schemas. Thus, I >>> receive the error message “Unknown type: >>> Q{urn:iso:std:iso:20022:tech:xsd:pain.001.003.03 }BICIdentifier”. >>> >>> >>> >>> Is there some workaround (other than rebuilding regular expressions from >>> schema to xquery)? >>> >>> >>> >>> Best regards, >>> >>> Ulrike.
UG
Ulrike Schaper - SideStep Business Solutions GmbH12 Mar 2016 21:39 #
Dear Christian,
Thanks a lot for your suggestions.
But as I stated in my original mail, I didn't plan to translate schema definitions to regular expressions... Neither did the validation module work as I hoped: Unfortunately the element in question is defined locally, not globally ("Validation failed: Deklaration des Elements 'BIC' kann nicht gefunden warden.").
So, back to regex, I suppose!
Best regards,
Ulrike.
Quoted text · Christian Grün · 94 lines
-----Ursprüngliche Nachricht----- Von: Christian Grün [mailto:christian.gruen at gmail.com] Gesendet: Freitag, 11. März 2016 11:29 An: Ulrike Schaper <U.Schaper at sidestep-solutions.de> Cc: basex-talk at mailman.uni-konstanz.de Betreff: Re: [basex-talk] How to check an element's type against an XSD simple type Sorry, a last one: Here is the fixed version of the query: declare variable $BIC-PATTERN := '^[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}$'; let $node := <BIC>GEN0DEM1MPW</BIC> return if(matches($node, $BIC-PATTERN)) then 'well done' else 'sigh' Most importantly, you’ll have to wrap your regex pattern with ^ and $ in order to ensure that there are no other heading or trailing characters in the BIC string. On Fri, Mar 11, 2016 at 11:23 AM, Christian Grün <christian.gruen at gmail.com> wrote: > PS: If it’s only about BIC validation, you can obviously use standard XQuery: > > declare variable $BIC-PATTERN := > '[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}'; > let $node := <BIC>GEN0DEM1MPW</BIC> > return if(matches($node, $BIC-) then 'well done' else 'sigh' > > > > > On Fri, Mar 11, 2016 at 11:20 AM, Christian Grün > <christian.gruen at gmail.com> wrote: >> Hi Ulrike, >> >> The Validation Module should help you here, in particular >> validate:xsd-report [1]. It allows you to pass on file URIs or XML >> fragments as arguments. >> >> All the best, >> Christian >> >> [1] http://docs.basex.org/wiki/Validation_Module >> >> >> >> On Fri, Mar 11, 2016 at 10:02 AM, Ulrike Schaper - SideStep Business >> Solutions GmbH <U.Schaper at sidestep-solutions.de> wrote: >>> Hi everybody, >>> >>> >>> >>> I’m trying to compose XML documents for SEPA transactions via BaseX. >>> >>> I would like to check certain data against the corresponding schema >>> before putting them into the document, e.g. BIC identifiers. >>> >>> >>> >>> In the xsd, there’s a simpleType definition for BICs: >>> >>> <xs:simpleType name="BICIdentifier"> >>> >>> <xs:restriction base="xs:string"> >>> >>> <xs:pattern >>> value="[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}"/> >>> >>> </xs:restriction> >>> >>> </xs:simpleType> >>> >>> >>> >>> I hoped it would be as simple as >>> >>> >>> >>> declare default element namespace >>> "urn:iso:std:iso:20022:tech:xsd:pain.001.003.03"; >>> >>> let $node := <BIC>GEN0DEM1MPW</BIC> >>> >>> return if(string($node) instance of BICIdentifier) then (true() (: >>> process... :)) else (false() (: report error :)) >>> >>> >>> >>> But, as I learned now, BaseX doesn’t support import of schemas. >>> Thus, I receive the error message “Unknown type: >>> Q{urn:iso:std:iso:20022:tech:xsd:pain.001.003.03 }BICIdentifier”. >>> >>> >>> >>> Is there some workaround (other than rebuilding regular expressions >>> from schema to xquery)? >>> >>> >>> >>> Best regards, >>> >>> Ulrike.
Written for BaseX 8.4. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery