Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: how to loop over nested yaml file content? Date: Sat, 23 Jan 2016 16:28:12 -0000 (UTC) Organization: A noiseless patient Spider Lines: 87 Message-ID: References: <83fb14d1-778c-44b8-bc6a-25742445c958@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sat, 23 Jan 2016 16:28:12 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="5e45ef46140b05dc5105f4b40d13e4a5"; logging-data="14790"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jpZb9k75NG5u73HF4SRfDhkZ4njG/zVc=" User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Cancel-Lock: sha1:1IvNz4voInSfQIhL4PLVsALnMK8= Xref: csiph.com comp.lang.java.programmer:33529 On Sat, 23 Jan 2016 07:52:23 -0800, Daniel Pitts wrote: > On 1/23/16 6:27 AM, Stefan Ram wrote: >> Mohammed Suleman khan writes: >>> I am having a .yml file that has nested level navigation >> >> public final class Main { >> >> private static final java.lang.String source = "navigationItems:\n" >> + >> "-\n" + >> " link: /features\n" + >> " label: Features\n" + >> "-\n" + >> " link: /contact\n" + >> " label: Contact Us\n" + >> "-\n" + >> " link: /about\n" + >> " label: About Us\n" + >> "-\n" + >> " link: /services\n" + >> " label: Services\n" + >> " navigationItems:\n" + >> " -\n" + >> " link: /service-1\n" + >> " label: Service 1\n"; >> >> public static void main(String args[]) throws Exception { final >> java.util.regex.Pattern p = >> java.util.regex.Pattern.compile ( "^ {6}([^ ].*)$", >> java.util.regex.Pattern.MULTILINE ); >> final java.util.regex.Matcher m = p.matcher( source ); >> while( m.find() )java.lang.System.out.println( m.group( 1 )); }} >> >> link: /service-1 label: Service 1 >> > Stefan: why are you using regex to parse Yaml? Yaml has a spec, and its > far more complex than your regex suggests. > > Mohammed: The problem is that you're trying to represent a tree > structure as a list. Really you need: > > class NavigationNode { > private List children; > private String label; > private String link; > } He has: class NavigationItem { String link String label List navigationItems } and also; I am using Jackson objectmapper to map the fields of yml with my mapper class like this: and; here I am trying to loop over it to get the all label, links and also the nested ones private String yamlToHtml() throws FileNotFoundException { String filePath = "src/main/resources/static/navigation/topnav.yml"; and; Navigation.groovy (?) in a couple places. all apparently to build some html; I am having a .yml file that has nested level navigation items that I am going to use for building the navigation. here my .yml file content. so that I'm not certain whether this cluelessness, trolling, or some highly developed workflow. > > > Then you can use recursion to go through the list. > > Hopefully this helps.