Re: Can default attibute values defined in xsd be referenced?
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
I'm very certain that FreeMarker exposes the default attributes just like if they were there (except when using @@markup and like, but that's not the case here). So perhaps the problem is with the way you create the W3C DOM tree. For example, are you sure that the parser that you are using is a validating one? -- Best regards, Daniel Dekany Friday, July 9, 2010, 2:45:35 PM, Altimes wrote: > I've been investigating using freemarker to generate code from XML embedded > in a source file. So far, so good. Then I thought I'd get a *little* bit > clevered and define attributes in the XSD with default values so that I > would not have to put them in the XML. I've checked the XSD and XML with > alternate tools, and they happily show me the default value of an attribute > that I do not supply in the XML (use="optional" default="123" in the xsd). > Sadly Freemarker has a bit of hissy fit with this. Throws the message > > "Expecting a string, date or number here, Expression entry.@storeSize is > instead a freemarker.ext.dom.NodeListModel" > > at me. A bit of investigation using entry.@storeSize?size (that I picked up > elsewhere in this forum, many thanks), showed 0 attributes. Which suggests > that the underlying parser is not working fully with the referenced XSD to > inject the missing nodes with their default values into the tree. > > I know that I can use the FTL, default value process, but that duplicates > the location that the value is stored and that just feels wrong.... > > Easier to manage > > <xsd:complexType name="fieldType"> > <xsd:sequence> > <xsd:element name="key" type="xsd:string"/> > <xsd:element name="type" type="xsd:string"/> > <xsd:element name="storeName" type="xsd:string"/> > <xsd:element name="storeLimitName" type="xsd:string"/> > </xsd:sequence> > <xsd:attribute name="storeSize" type="xsd:positiveInteger" > default="25" use="optional"/> > </xsd:complexType> > > than to find multiple "25"s buried inside a couple of hundred lines of > template scripting for each occurence of the attribute. > > Hopefully I am wrong and just need advice on the > freemarker.ext.dom.NodeModel API to call a like > ...setUseDefault(true) > that I cannot find (or perhaps do not recognize). > > TIA. > > Alan. > > > > ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first