Skip to content


Repository files navigation

CN1 XMLView Library

A codename one UI component for rendering XML. This is similar to an HTML renderer except it is far simpler, performant, and pluggable. It is useful for displaying rich content (text, images, videos) within a Codename One form.


Apache 2.0


  • Light-weight component.
  • Comes with support for minimal set of tags: <p>, <img>, <carousel>, and <video>.
  • Pluggable. Add your own views and support your own custom tags by implementing your own view factory.
  • Easily Styleable. All built-in components support the uiid attribute which specifies the UIID to use for styling the component.


Copy xmlview.cn1lib into your project's "lib" directory and refresh libs.

Usage Example

Form hi = new Form("Wiki News Feed");
hi.setLayout(new BorderLayout());
XMLView xmlView = new XMLView();
new DefaultXMLViewKit().install(xmlView);

// Loading XML from a string
xmlView.setXML(Util.readToString(Display.getInstance().getResourceAsStream(null, "/SampleNewsFeed.xml"), "UTF-8"));

// Alternate syntax loading XML from a URL.
//xmlView.load("", new Callback<Element>() {
//    public void onSuccess(Element root){ ... }
//    ....
hi.addComponent(BorderLayout.CENTER, xmlView);;

What it looks like:


How it Works

This component will parse XML content that is provided to it (either from an XML string or a XML page URL), iterate through the top-level XML tags in the document, and for each tag, generate an appropriate view for it. The generated views are laid out down the XMLView component vertically (using BoxLayout Y_AXIS).

E.g. Given the following XML:

<?xml version="1.0"?>
    <p>Hello World</p>
    <img src=""/>
    <p>Goodbye World</p>

The XMLView would render three views vertically. The type of component returned, depends on the registered ViewFactory for that tag name. The default editor kit uses a view factory that generates a SpanLabel component for each paragraph, and a Label for each image. But you could easily register your own ViewFactory to generate a different component.


This is not meant to be a full HTML renderer. If you look at most "feed" type apps, like Facebook, Twitter, and the like, they don't perform complex page rendering. They usually just display paragraph text, images, and videos in a responsive format, where images are all square, videos are 16x9, and both images and videos span the width of the parent component (and often the full device width). That is the kind of thing that this component excels at.

For rendering, this component doesn't traverse down the hierarchy of the XML document. It merely takes the top-level children, and passes each to the appropriate view factory, and lays out the components returned from the view factory vertically (in a box layout).


Building From Source

$ git clone
$ cd cn1-xmlview
$ ant -f configure.xml
$ ant jar

You'll find xmlview.cn1lib inside the dist directory.

NOTE: The ant -f configure.xml is only necessary the first time you build the source. It will download some dependencies like JavaSE.jar, CodenameOne.jar, etc.. that were not included with this repository to save space.


XMLView library for Codename One







No releases published


No packages published