Upload
falk-hartmann
View
446
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
Falk HartmannResearch Associate, SAP AG
An Architecture for an XML-Template Engine enabling Safe Authoring
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 2
2/25Agenda
Motivating Example
Definitions
Goals
Requirements
Proposed Architecture
Solution Elements
Related Work
Conclusion & Open Issues
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 3
3/25
Servlet Container
Template(JSP)
Template(JSP)
Data Tier
Motivating Example
Safe Authoring:Ensure, that the instantiated template conforms to
the target language by inspecting the template!
BrowserJSP EnginePage
(XHTML)
User
Author
Page(XHTML)
Browser
Data
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 4
4/25
JSP
Definitions
Binding Language
<%= table.date() %>
Slot Markup Language
<%= %>
Term Language
table.date()
= +
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 5
5/25Goals
Safe Authoring
All errors detectable upfront are indeed detected upfront
Structural errors like incorrectly nested elements, missing attributes
Separation of Concerns
Templates are a mean for separation of concerns
Concerns depend on use case, e.g., between web designer and developer
Adequate Error Handling
Errors are clearly and understandably signaled to the user
Both for errors detectable upfront and at runtime
Broad applicability
Restriction on target language: XML
No restrictions on the instantiation data (esp. its addressing)
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 6
6/25Requirement 1: Preservation
Goals: Safe Authoring
A template engine and language must preserve all constraints that are valid in the target language also in the template language.
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 7
7/25Requirement 2: Coverage
Goals: Broad Applicability, Separation of Concerns
The template language should cover the target language by allowing to produce every target language document from a template, no matter which parts of the target language document are created from the instantiation data.
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 8
8/25Requirement 3: Inferibility
Goals: Safe Authoring, Broad Applicability
It must be possible to automatically infer the schema the template must comply to from the schema defined for the target language.
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 9
9/25Requirement 4: Control
Goals: Separation of Concerns
The binding language must support control statements for conditional and repeated inclusion of template fragments.
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 10
10/25Requirement 5: Type safety
Goals: Adequate Error Handling
In order to assert, that the instantiated template complies to the target language schema the types of the instantiation data must be correct.
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 11
11/25Requirement 6: Independence
Goals: Broad Applicability
The architecture should be independent of the data source and the way data in it is addressed.
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 12
12/25Proposed Architecture
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 13
13/25Solution Element 1: Binding Language Design
Requirements: Coverage, Control, Independence
General: Independence makes reasoning about instantiation data impossible
No switch statements which allows multiple branches
Coverage and control imply the necessity for conditional and repeated content
XML Specific: Leverage namespaces as concept for slot markup language
No extra markup, existing tools can be reused
XTL = XML Template Language
Prototypical approach: XTL is embedded into target language
Elements: xtl:text, xtl:attribute, xtl:if, xtl:for-each
Decision against xtl:element
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 14
14/25…Prototypical vs. Transformational Approach
Prototypical Approach:Target language syntax is "top-level" syntaxBinding language syntax is embedded
JSP: <html>…<%= name %>…</html>
+target language syntax checkable (with limitations improvable)
+easier to learn
Transformational Approach:
Binding language syntax is "top-level" syntaxTarget language fragments are embedded
XSLT: <xslt:transform>…<html>…</html>…</xslt:transform>
+binding language syntax checkable
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 15
15/25Solution Element 2: Grammar Transformer
Requirements: Preservation, Inferibility
General: Separation of constraints: upfront checkable and instantiation data
XML Specific: Target language grammar (input): XML Schema Template language grammar (output): not expressible in XML Schema
→ enhancement of XML Schema with OCL constraints (CXSD) Schema without constraints should not declare valid templates invalid Instantiation data constraints: XML Schema Types
Enabling xtl:attribute for all elements with attributes Enabling xtl:if/xtl:for-each around elements with appr. multiplicity Forcing ID to be replaced by xtl:attribute in xtl:for-each
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 16
16/25
Problem:
- Attribute might be substituted by xtl:attribute
- Change of content model and attribute model
Current Approach:
<element name="external-graphic"> <complexType> <attribute name="src" type="string" use="required"/> </complexType></element>
Problem:
- Attribute might be substituted by xtl:attribute
- Change of content model and attribute model
Current Approach:
<element name="external-graphic"> <complexType> <sequence> <element ref="xtl:attribute"/> </sequence> <attribute name="src" type="string" use="optional"/> </complexType></element>
<element name="external-graphic"> <annotation> <appinfo source="…"> <cxsd:inv> let count : Integer = self->select(xtl:attribute[@name='src'])->size() in if @src->isEmpty() then count = 1 else count = 0 endif </cxsd:inv> </appinfo> </annotation> <complexType> <sequence> <element ref="xtl:attribute"/> </sequence> <attribute name="src" type="string" use="optional"/> </complexType></element>
… Enabling xtl:attribute
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 17
17/25… Enabling xtl:if/xtl:for-each
Problem:- Modeling as attribute vs. as element
- Definition of xtl:if/xtl:for-each with wildcard (lax processing)
- Problem: asserting local validity
Current Approach:
<element name="label" type="string" minOccurs="0"/><element ref="xtl:if"> <annotation> <appinfo source="http://research.sap.com/cxsd/1.0"> <cxsd:element name="label" type="string"/> </appinfo> </annotation></element>
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 18
18/25… Forcing ID to be replaced
Problem:
-Attributes and elements with type 'ID' must be instantiation data inside xtl:for-each
-Treatment of IDREF unsolved (conversion to string?)
Current Approach:
<cxsd:inv> let count : Integer = self->select(ancestor::xtl:for-each->size()) in count > 0 implies count(@id-attribute) = 0</cxsd:inv>
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 19
19/25Solution Element 3: Template Validator
Requirements: Preservation
General: Grammar checking tool
Depending on template language grammar used
XML Specific: XML Schema with OCL constraints
OCL navigation expressions replaced by XPath
Implementation via XMLBeans and Dresden OCL Toolkit
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 20
20/25Solution Element 4: Template Engine
Requirements: Control, Independence
General: Enable independence using plug-in architecture
XML Specific: Efficient (memory, time) implementation not straight-forward
SAX implementation hard due to necessary look-ahead
StAX allowed an efficient implementation based on a two-stream machine
Linear Memory and Time Complexity
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 21
21/25Solution Element 5: Term Evaluator
Requirements: Independence
General: Term evaluation outsourced from template engine
XML Specific: Implementation of XPath plug-in makes XTL comparable to XSL-T
XTL cannot be translated directly to XSL-T as this would require dynamic evaluation of XPath (however, with this feature or with a two-stage XSL-T it is possible)
Implementation of OCL plug-in plannedOCL plug-in would enable efficient generation of XML documents from UML
models (XMI, XML Schema using the corresponding profile)
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 22
22/25Solution Element 6: Inst. Data Validator
Requirements: Type Safety
General: Enables exact error messages in case of mismatching instantiation data
types
XML Specific: Only simple types
Straight-forward, check using XMLBeans
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 23
23/25Related Work
• T. J. Parr: Enforcing strict model-view separation in template engines. WWW’04
• S. Maneth, A. Berlea, T. Perst, and H. Seidl: XML type checking with macro tree transducers. PODS’05
• M. Murata, D. Lee and M. Mani:Taxonomy of XML Schema Languages using Formal Language Theory.Extreme Markup Languages 2001
• V. Wallentine, S. Zhou:Validating XML Document Content with the Object Constraint Language.Documents in Computing and Information Science 2002
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 24
24/25Conclusions & Open Issues
Conclusions:
- Safe authoring can be supported with this architecture
- XML Schema wildcards lack expressive power
- XML Schema transformations are hard to implement
Open Issues:
- Search existing XML Schema transformation engines
- Alternative schema languages
- Define white space handling
- Treatment of identity constraints
SAP AG 2006, An Architecture for an XML-Template Engine… / Falk Hartmann / 25
25/25Questions
Thank you very much!
Questions…?