« Home « Kết quả tìm kiếm

XML Patterns


Tóm tắt Xem thử

- The patterns use the power of XML to share data between distributed sources as well as to transform XML data on behalf of the user view..
- Each pattern uses XML, the eXtensible Markup Language, to form part of the solution.
- The XML specification offers a way of organizing data so that the data can be shared.
- In this pattern, XML holds the place of the in and out trays that a worker uses to receive petitions.
- Here XML data on one side and the instructions in the XSL stylesheet on the other feed a transformation process that generates output in the form of an HTML file.
- incorporated to the output, always keeping high modularity and clear distinction of the responsibilities of each component..
- This process takes the different feeds and builds a compilation of the data in an XML document, even when foreign applications run on different platforms.
- The complete code for the implementation of the examples present in all the patterns can be found in [Lifia xml]..
- Organize the activity of components involved in the process of getting and showing data..
- We don’t need all the data held by the source, but some of it.
- But in the interchanging process only data are interchanged..
- This is messy, and could lead to too many entrances in the data source looking for the data.
- therefore forces the developer to understand the data model of the source, and also increases programming efforts and coupling between the internal components.
- So the only requirements are that the WORKER must understand the request and the format (structure) of the XML file.
- The WORKER then processes the data and adds a business rule if needed.
- But once WORKER finds out the results, it transfers them to OUT, and OUT performs the formatting and transformation (in the XSLT sense) of the results..
- OUT gets the data and builds the output, formatting, transforming and rendering them.
- OUT is designed upon the output device, in the same way as IN is designed upon the input device..
- The XML files store the data.
- Figure 1.1 shows component connections..
- Figure 1.1 Relation between components present in the solution WORKER.
- Here we included in the patterns only part of the code.
- First of all we used the XML document to store the data in our catalog.
- Figure 1.2 shows part of the XML file and the data format we’ve chosen..
- The list of products present in the catalog is composed of a list of <items>.
- So we built worker.asp, a program to do the work of the component WORKER and we also built out.asp, a program to do the work of the OUT component.
- Figure 1.4 shows part of the worker.asp’s code and Figure 1.5 shows the output presented to the client..
- Figure 1.2 Part of a catalog in a.
- Using the file worker.asp, we look for the data we need in the XML document (storage.xml) and show it..
- Figure 1.5 Output presented to the client.
- This pattern wouldn’t apply when the components depend heavily on each other in the sense that one component uses code elements that belong to another..
- When rendering the data with the OUT component, or after retrieving the data from the XML file with the WORKER, we can group selected data using Information Grouping, a pattern we describe below..
- Furthermore, a key benefit in the design is the use of XML to assure platform independence.
- In the implementation XML acts as a gateway connecting the system that uses this design and neighbours with which the system has to interact..
- The XML document plus the programming of the part of WORKER that gets the data from a foreign system provides a placeholder to control access to the data.
- It is a common problem to break a simple architecture to add some kind of computation that performs work needed as part of the output, for instance the task to calculate some value upon some of the data received.
- This leads to complex and expensive code both in writing and in maintenance, and this in turn ends up raising the cost of the whole system..
- In calculating some value based upon some of the data, for example, we need to figure or fetch some information by some kind of computation that we do not wish to include in the stylesheet, even if the expression relies upon the XML data stored in an XML document..
- If we are working in a context where we need to keep data separate from instructions by using XML and XSLT, adding tasks can increase the complexity of the code.
- have a XSL stylesheet with precise instructions about what to do with the data.
- But the process is aided by an external function that adds functionality and then improves the behavior defined in the stylesheet.
- Figure 2.1 shows the sketch of the solution..
- Figure 2.3 shows part of the code of the stylesheet..
- Figure 2.2 XML document dummy.xml.
- Figure 2.3 Part of the stylesheet external.xsl calling a method.
- Here we show how to call a method of the Java standard class library.
- start with the same dummy.xml file used in the previous example.
- We keep high modularity because we add external computations maintaining the abstraction of the behavior.
- We avoid mixing external code with the code needed to show the XML data, which is in the stylesheet..
- It will probably become a standard in the future [Kay00]..
- Since at the time of writing it is not defined in the XSLT or XPath specification, care must be taken, because using this mechanism lowers the portability of the stylesheet considerably.
- If the developers call a Java class, since it is not still written in the spec, the way they call it depends on the processor.
- That is because the XSLT spec includes sorting, which is prima facie evidence that this sort of computation should be handled in the stylesheet.
- But when the process that needs to be performed isn’t included in the XSLT specification, then External Assistant can help..
- Given an XML document, the pattern shows the way to format the XML data and generate an HTML file containing the data of the XML document, but grouped by certain criteria..
- The stylesheet instructs a program (a parser) what to do with the data stored in the XML file.
- It specifies a transformation (in the XML sense, since data in the original file remains the same) that traverses the XML tree implicit in the XML file that has the data, and makes a new list which has all the groups existing in the tree.
- In a second step, the transformation loops through the distinct group list generated previously in such a way that for each group in this list, it inserts a row in a table that will be shown in the output.
- It renders the desired part of each element in the corresponding element of the HTML file.
- For instance it prints part of the element in the second column of the corresponding row of a table.
- The group to which the element belongs is the deciding factor of the proper row.
- Figure 3.1 Transformation process.
- Now we need to work with the data so we can transform the XML tree to get another XML tree with the same data, but ordered as we want to show it.
- So we create a stylesheet that tells the parser to produce an HTML file showing the data in conformance with our specification.
- Figure 3.2 Part of list.xml.
- Figure 3.4 HTML showing data grouped by the value of the <group>.
- There’s a clear gap between the data content and representation format.
- Besides, a change in the transformation doesn’t affect data.
- While keeping consistency between XML document and tags used in the transformation, a change in one doesn’t affect the other..
- Note that there are some restrictions to the file storing the data, for instance that the data must be an XML document.
- But this fact leads to an increase in the number of contexts (situations) where we can apply Information Grouping with low effort..
- For instance if the XML document that stores the data have elements with attributes, then this pattern can be used to group by attributes as well..
- Information Grouping should be called if the calculation we want to apply to the data is included in the XSLT specification.
- This stands in contrast with External Assistant, which should be called when the data processing includes some specific calculation that is not part in the specification or, even if specified, will require code that is hard to write..
- Nevertheless, when Information Grouping is used, it could be used with External Assistant to add processing without breaking the architecture of the Information Grouping’s approach..
- Besides, we need some inner validation for the data carried, in order to verify that we’ve received all the data that were sent.
- For instance, if we were carrying an invoice, we would need to guarantee that we’ve received every item of it in the transaction, and that none was left out due to problems in the transference..
- This is because adding the connection involves adding programming, and the new component shouldn’t interfere with the design of the site.
- Each application that wishes to offer information should add a component from which clients can take formatted information or have an additional process outside of the foreign system to format the data into an XML valid format for the clients to consume that data.
- Once the user has found what he’s looking for, he can order the download of the data avoiding the task of copying and pasting data..
- The information collector component acts under user guidance and plugs into the connecting component, its mating component on the side of the application that’s offering information..
- Once the user has found the information on one of the servers, the client connects its information collector to the server’s connecting component and starts the XML data transmission.
- After receiving this server data, the client connects its information collector to the connecting component of the other server and repeats the process.
- By doing this, the client creates an XML data pool with the information obtained in the web sites.
- The user can then edit this file with a text editor as well as with any of the XML editor available..
- Furthermore, the data obtained can directly feed specific user’s application..
- We get a modular solution that allows clean sharing of data between non-related components, avoiding one’s interference in the other’s affairs.
- In addition we don’t interfere with internal data representation in the source, nor in the client..
- It even could connect to non-standard devices without a significant change in the code..
- We just add a token of the connection component..
- This pattern is a mediator in the sense of the GoF pattern Mediator [Gamma+95].
- In the implementation we suggest the use of XML to share information because XML is an effective way to transmit structured information between non-related applications.
- In the implementation, servers and clients are responsible for giving context information (if needed).
- Intrinsic state is stored in the objects and it is information that is independent of the object context, and thereby sharable.
- Besides, as shown in the example, we can develop an XML structure to store gathered data and read it from the XML document using a text editor, an XML editor or a custom application specially designed to process that data..
- [W3CDOM] Document Object Model (DOM) Level 2 Specification Version 1.0 Candidate Recommendation of the World Wide Web Consortium, http://www.w3.org/TR/REC-DOM- Level .
- [W3CNamespaces] Extensible Markup Language (XML) Specification Version 1.0 Recommendation of the World Wide Web Consortium, http://www.w3.org/TR/REC-xml- names .
- [W3CXML] Extensible Markup Language (XML) Specification Version 1.0 Recommendation of the World Wide Web Consortium, http://www.w3.org/TR/REC-xml .
- [W3CXPATH99] XML Path Language (XPath) Version 1.0 Recommendation of the World Wide Web Consortium, http://www.w3.org .
- [W3CXSLT] XSL Transformations (XSLT) Version 1.0 Recommendation of the World Wide Web Consortium, http://www.w3.org

Xem thử không khả dụng, vui lòng xem tại trang nguồn
hoặc xem Tóm tắt