XML may consist of many layers of nested elements, based on the requirements of the data. The great thing about Crystal Reports in this situation is that any number of groupings can be applied to help aid in the nesting of your XML.
To continue that idea of well-formed XML, indent each level with two spaces. This will ensure that when viewed externally, the final XML output will align properly and be more easily viewed.![]()
The simple handler here is that if the value for Country is null, still create the opening and closing tags for the element.
Next, consider the effect of using a numeric value in the XML.
![]()
If Revenue is null, display 0. Also, when displayed, we can set the decimal places to 0 and ensure that no separator is placed within the XML (that’s important). If it has a comma in the output, the XML data may be identified as a string value instead of numeric later.
These illustrations are just two examples of the many complexities and business rules you can enforce in the formulas prior to actually rendering this information within the XML itself.
Create the XML body
With all of our formulas in place, the best way to construct the body of the result is to use a text object in the report body. In the detail section, add a text object and with the appropriate number of spaces in front of each variable, and insert as shown here.
Note that the container element in this case is child_element. This element should open and close each detail record in the output.
Close the report out with a footer that matches the opening parent tags at the top and you’ve created some well-formed XML.
Last bits
Conclusion
XML is an extremely powerful way to share data. In this illustration, root_element and parent_element don’t really mean anything. However, these could have been replaced with groups on the Country and Resort to further enforce the hierarchy of the XML data.
Using Crystal Reports is a great way to rapidly create XML structures and automate the publication of this XML via the Business Objects platform.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24260552/viewspace-740640/ ,如需转载,请注明出处,否则将追究法律责任。