Coder Social home page Coder Social logo

nested-set-model-api's Introduction

Nested-Set-Model-API

Java class to make it easy to generate nested set model left and right values from given xml. Very generic, should work with all well-formed XML. Uses org.w3c.dom for traversal in conjunction with Xpath

The nested set model makes it easy to store heirarchical data in a database. However, it needs that the pre-order traversal be made such that every node is visited twice and assigned "left" and "right values"

Details are over at http://en.wikipedia.org/wiki/Nested_set_model

Sample usage of this class:

File xmlFile = new File("src/sampleHtml.xml"); //xml file
XmlWalk xmw = new XmlWalk(xmlFile, new String[]{}); //pass empty string, for no exclusions (or null)
result = xmw.getResult(); //fetch results
for(ExtendedNode en : result){ //iterate through results
	System.out.println(en.getNode().getNodeName() + " --> " + en.getLeft() + " : " + en.getRight());
}

Similarly, it can be used with xml strings as input. It allows skipping certain tags, from the entire traversal itself. They can be passed as a string array, in the constructor itself.

It retrieves results in an ArrayList of ExtendedNode objects. Further additions can be made to ExtendedNode, if necessary.

Try TestXmlWalk to get an idea: ##Input:

<html>
	<head>
   		<title>bux</title>
	</head>
	<body>
		<div>
			<div>1.1</div>
			<div>1.2></div>
		</div>
		<div>2</div>
	</body>
</html>

##Output (no exlusion, pre-order):

Node-name  Left   Right
html        1     16
head        2     5
title       3     4
body        6     15
div         7     12
div         8     9
div         10    11
div         13    14

##Why this output:

                                   html (1,16)
                                    |
                                    |
                              -------------
                             |             |
                          head(2,5)     body(6,15)
                             |             |
                         -----         ----------
                        |             |          |
                    title(3,4)    div(7,12)    div(13,14)
                                      |
                                  ---------
                                 |         |
                              div(8,9)  div(10,11)

nested-set-model-api's People

Contributors

foxish avatar ch261049 avatar

Stargazers

SeungwanJo avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.