The length of this element should be more than 1 character

Suppose I have a text element whose length must be greater than 1 character. I think an assert should be able to handle this, and there's a string-length() function, so I wrote this for my xPath expression: fn:string-length(.) > 1 But MBTK is telling me: CTDX1100E : XSD: The attribute 'null' is not permitted (This is, BTW, a less-than-helpful error message.) [cid:image001.png@01CE3200.633AA6A0] I added it manually, like so: <xsd:element name="Body" type="xsd:string"> <xsd:annotation> <xsd:appinfo source="http://www.ogf.org/dfdl/"> <dfdl:assert message="The length of the body must be more than 1 character"> { fn:string-length(.) > 1 } </dfdl:assert> </xsd:appinfo> </xsd:annotation> </xsd:element> And MBTK gave me this error: CTDV1493E : XPath expression '{ fn:string-length(.) > 1 }' contains a path expression that does not resolve to an element in the schema: 'Found ">" at line 1, column 23. Expected one of "}" "or" "and" "*" "div" "idiv" "mod" "eq" "ne" "lt" "le" "gt" "ge" "[" "-" "+" "/"'. Element: #xmlns(p="http://fileid")xscd(/schemaElement::p:ImfMime/type::0/model::sequence/schemaElement::Body). So this indicates it doesn't like the ">" character. So I changed it to > but got the same message. So am I implementing this wrong? Or does MBTK not support this function? Daffodil is also giving me an error: Schema Definition Error: XPath Compilation Error: net.sf.saxon.trans.XPathException: XPath syntax error at char 20 in {fn:string-length(.) > 1}: Prefix fn has not been declared Schema context: element.Body. Location in file:/C:/Users/jgarriss/daffodil-0.8.1/bin/DetectImfMime.xsd But this is a different issue, a namespace issue. MBTK magically knows about the "fn:" namespace, but Daffodil doesn't. It's not declared in the root element: <?xml version="1.0" encoding="UTF-8"?> <xsd:schema targetNamespace="http://fileid" xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/" xmlns:fmt="http://www.ibm.com/dfdl/GeneralPurposeFormat" xmlns:ibmSchExtn="http://www.ibm.com/schema/extensions" xmlns:ns0="http://fileid" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> Help!

To use the fn: function namespace, I believe it must be declared in the xs:schema element. xmlns:fn="http://www.w3.org/2005/xpath-functions" see: http://www.w3.org/TR/xpath-functions/#namespace-prefixes. By incorporating all these XPath functions, and using the same 'fn:' prefix syntax, the DFDL spec strongly implies that the namespace is required to be the same. So I don't believe this should be built in anywhere by a DFDL implementation. The spec doesn't say it should be anywhere to my knowledge. (Correct me if this is wrong.) The Daffodil implementation requires this namespace prefix to be declared like above, and adding it should fix your bug, or at least get you to the next issue. I'm happy with the error message you got from daffodil. Not that we don't have plenty of other obscure ones that we need to fix, but this one we got right it looks like. As for the '>', the message says you should use "gt", not ">" which would be HTML-style escaping. ...mike On Fri, Apr 5, 2013 at 1:44 PM, Garriss Jr., James P. <jgarriss@mitre.org>wrote:
Suppose I have a text element whose length must be greater than 1 character. I think an assert should be able to handle this, and there’s a string-length() function, so I wrote this for my xPath expression:****
** **
fn:string-length(.) > 1****
** **
But MBTK is telling me:****
** **
CTDX1100E : XSD: The attribute 'null' is not permitted****
** **
(This is, BTW, a less-than-helpful error message.)****
** **
****
** **
I added it manually, like so:****
** **
<xsd:element name="Body" type="xsd:string">****
<xsd:annotation>****
<xsd:appinfo source="http://www.ogf.org/dfdl/">****
<dfdl:assert message="The length of the body must be more than 1 character"> ****
{ fn:string-length(.) > 1 }****
</dfdl:assert>****
</xsd:appinfo>****
</xsd:annotation>****
</xsd:element>****
** **
And MBTK gave me this error:****
** **
CTDV1493E : XPath expression '{ fn:string-length(.) > 1 }' contains a path expression that does not resolve to an element in the schema: 'Found ">" at line 1, column 23. Expected one of "}" "or" "and" "*" "div" "idiv" "mod" "eq" "ne" "lt" "le" "gt" "ge" "[" "-" "+" "/"'. Element: #xmlns(p=" http://fileid ")xscd(/schemaElement::p:ImfMime/type::0/model::sequence/schemaElement::Body). ****
** **
So this indicates it doesn’t like the “>” character. So I changed it to > but got the same message.****
** **
So am I implementing this wrong? Or does MBTK not support this function?* ***
** **
Daffodil is also giving me an error:****
** **
Schema Definition Error: XPath Compilation Error: net.sf.saxon.trans.XPathException: XPath syntax error at char 20 in {fn:string-length(.) > 1}:****
Prefix fn has not been declared Schema context: element.Body. Location in file:/C:/Users/jgarriss/daffodil-0.8.1/bin/DetectImfMime.xsd****
** **
But this is a different issue, a namespace issue. MBTK magically knows about the “fn:” namespace, but Daffodil doesn’t. It’s not declared in the root element:****
** **
<?xml version="1.0" encoding="UTF-8"?>****
<xsd:schema targetNamespace="http://fileid"****
xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/" xmlns:fmt=" http://www.ibm.com/dfdl/GeneralPurposeFormat"****
xmlns:ibmSchExtn="http://www.ibm.com/schema/extensions" xmlns:ns0="http://fileid"****
xmlns:xsd="http://www.w3.org/2001/XMLSchema">****
** **
Help!****
-- dfdl-wg mailing list dfdl-wg@ogf.org https://www.ogf.org/mailman/listinfo/dfdl-wg
-- Mike Beckerle | OGF DFDL Workgroup Co-Chair | Tresys Technology | www.tresys.com
participants (2)
-
Garriss Jr., James P.
-
Mike Beckerle