简体   繁体   中英

Generate html output using java

I would like to generate a html output like below based on the list.The list will be generated from the content available in xml file.Using XMLEventReader able to read the menu file and generating a list which contains the following details Menu Name,depth,number of children and who is their parent. Now I was able to generate the output but when submenu comes into picture the output is collapsed.Moreover I'm not sure how to implement the recursion while checking the submenu.It would be really very helpful if anyone help me on this.

        Here follows the expected html output
         The htmloutput looks like below 
            <li><a >Item 1</a>
                        <ul>
                            <li><a >Item 1.0</a>
                                <ul>
                                    <li><a >Item 1.0.0</a></li>
                                </ul>
                            </li>

                            <li><a >Item 1.0.1</a></li>

                            <li><a >Item 1.0.2</a>
                                <ul>
                                    <li><a >Item 1.0.2.0</a>
                                        <ul>
                                            <li><a >Item 1.2.0.1</a></li>
                                        </ul>
                                    </li>


                                </ul>
                            </li>
                        </ul>
                    </li>


        Here follows code snippet of menu file

            <?xml version="1.0" encoding="UTF-8"?>
                <Menu name="Item 1">
                    <Menu name="Item 1.0">
                        <MenuItem>
                            <Name>Item 1.0.0</Name>             
                        </MenuItem>
                        <MenuItem>
                            <Name>Item 1.0.1</Name>

                        </MenuItem>
                        <Menu name="Item 1.0.2" >
                            <MenuItem>
                                <Name>Item 1.0.2.0</Name>                   
                            </MenuItem>
                        </Menu>
                    </Menu>
                </Menu>

You could use Java to run an XSL transformation:

http://docs.oracle.com/javaee/1.4/tutorial/doc/JAXPXSLT6.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM