Featured post
java - Achieve the xml hierarchy structure having an ordered list with level numbers -
i have list of numbers represents levels in xml tree. example have folowwing list:
0, 1, 2, 2, 1
and xml (with 'lev' elements) needs be:
<lev> <lev> <lev> </lev> <lev> </lev> </lev> <lev> </lev> </lev>
how can form xml having list? need recursive method, need xsl file, great having java code - parsing list.
i'm not sure if possible, having list. great! thanks.
later edit:
for above list let's introduce position too:
level position 0 0 1 1 2 2 2 3 1 4
if having in list number(level) x , after having number(level) y y<=x know @ point last element(s) (x, x-1, ..., y) needs closed when creating xml.
ex.:
when @ position 3 (level 2) know element @ position 2 (also level 2) needs closed
when @ position 4 (level 1) know element @ position-s 3 (level 2) , 1 (level 1) needs closed
recursion overkill this. also, there's no need "position" value. here's pseudocode solution
assume function next()
returns next input value, or 0 eof.
curlevel = 0 n = next(); { while(curlevel <= n) { open tag ++curlevel } n = next(); while(curlevel > n) { --curlevel close tag } } while(curlevel > 0)
note corner case of empty input file produce 1 open/close pair. check eof different way , modify code handle if that's not desired.
- Get link
- X
- Other Apps
Comments
Post a Comment