<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: loop xml attributes in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/loop-xml-attributes/m-p/232963#M194796</link>
    <description>&lt;P&gt;Excuse me &lt;A rel="user" href="https://community.cloudera.com/users/2119/pchallauk.html" nodeid="2119"&gt;@Pavan Challa&lt;/A&gt;, I should have looked at the related question more carefully.&lt;/P&gt;&lt;P&gt;So, what you'd like to do is looping through 'dataFlow' elements to find one which has 'filePattern' that matches with the name of incoming file? If so, that might be too much to do with XMLFileLookupService. I'd write a script with ExecuteScript that parses the XML file and do the matching.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jul 2017 19:09:46 GMT</pubDate>
    <dc:creator>kkawamura</dc:creator>
    <dc:date>2017-07-11T19:09:46Z</dc:date>
    <item>
      <title>loop xml attributes</title>
      <link>https://community.cloudera.com/t5/Support-Questions/loop-xml-attributes/m-p/232960#M194793</link>
      <description>&lt;P&gt;We have the below xml configuration as input to get the to-path value to put files.&lt;/P&gt;&lt;PRE&gt;&amp;lt;configuration verbose="false" debugMode="false"&amp;gt;
	&amp;lt;dataFlows&amp;gt; 		
		&amp;lt;dataFlow&amp;gt;
			&amp;lt;properties&amp;gt; 				
				&amp;lt;dept&amp;gt;salary&amp;lt;/dept&amp;gt;
				&amp;lt;version&amp;gt;1.0&amp;lt;/version&amp;gt;			
			&amp;lt;/properties&amp;gt;
			&amp;lt;filePattern&amp;gt;salary_*.gz&amp;lt;/filePattern&amp;gt; 	
			&amp;lt;to&amp;gt;				
				&amp;lt;path&amp;gt;d_${dept}/${version}/csv&amp;lt;/path&amp;gt; 			
			&amp;lt;/to&amp;gt; 		
		&amp;lt;/dataFlow&amp;gt; 
		&amp;lt;dataFlow&amp;gt;
			&amp;lt;properties&amp;gt; 				
				&amp;lt;dept&amp;gt;pension&amp;lt;/dept&amp;gt;
				&amp;lt;version&amp;gt;2.2&amp;lt;/version&amp;gt;			
			&amp;lt;/properties&amp;gt;
			&amp;lt;filePattern&amp;gt;pension_*.gz&amp;lt;/filePattern&amp;gt; 	
			&amp;lt;to&amp;gt;				
				&amp;lt;path&amp;gt;d_${dept}/${version}/csv&amp;lt;/path&amp;gt; 			
			&amp;lt;/to&amp;gt; 		
		&amp;lt;/dataFlow&amp;gt; 	
	&amp;lt;/dataFlows&amp;gt; 
&amp;lt;/configuration&amp;gt;&lt;/PRE&gt;&lt;P&gt;I have followed the &lt;A target="_blank" href="https://community.hortonworks.com/questions/109613/nifi-lookupattribute-and-updateattributes.html"&gt;nifi-lookupattribute-and-updateattributes&lt;/A&gt; to handle a single &amp;lt;dataFlow&amp;gt;. Thanks to &lt;A rel="user" href="https://community.cloudera.com/users/2956/jfrazee.html" nodeid="2956"&gt;@jfrazee&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Does anyone know how to loop attributes? I will be having 100s of &amp;lt;dataFlow&amp;gt; attributes in a single xml config file. I have added just 2 in the above example.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 16:20:09 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/loop-xml-attributes/m-p/232960#M194793</guid>
      <dc:creator>pchallauk</dc:creator>
      <dc:date>2017-07-10T16:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: loop xml attributes</title>
      <link>https://community.cloudera.com/t5/Support-Questions/loop-xml-attributes/m-p/232961#M194794</link>
      <description>&lt;P&gt;Hello &lt;A rel="user" href="https://community.cloudera.com/users/2119/pchallauk.html" nodeid="2119"&gt;@Pavan Challa&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Probably SplitXml processor will be helpful. Specify depth '2' and you'll get FlowFiles having only single 'dataFlow' element as its content.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 12:23:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/loop-xml-attributes/m-p/232961#M194794</guid>
      <dc:creator>kkawamura</dc:creator>
      <dc:date>2017-07-11T12:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: loop xml attributes</title>
      <link>https://community.cloudera.com/t5/Support-Questions/loop-xml-attributes/m-p/232962#M194795</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/3908/kkawamura.html" nodeid="3908"&gt;@kkawamura&lt;/A&gt;, Thanks for your response. In my case, the FlowFiles are not xml files. It will be txt or gz files. So I will be using LookupAttributes (which will be using XMLFileLookupService) to read the XML config file (shown above) for to-path to put FlowFiles (*.txt or *.gz) into destination path (to-path: ex: /d_salary/1.0/csv or /d_pension/2.2/csv). So I need to know the way to loop my XML config file.&lt;/P&gt;&lt;P&gt;I have missed add one more attribute in XML config file. I will be having something like below for each dataFlow.&lt;/P&gt;&lt;PRE&gt;&amp;lt;filePattern&amp;gt;salary_*.gz&amp;lt;/filePattern&amp;gt;

&amp;lt;filePattern&amp;gt;pension_*.gz&amp;lt;/filePattern&amp;gt;&lt;/PRE&gt;&lt;P&gt;I will correct my above XML file. So if I have salary_*.gz, the file should be moved to /d_salary/1.0/csv. If I have pension_*.gz then it should be moved to /d_pension/2.2/csv. &lt;/P&gt;&lt;P&gt; Any help is much appreciated. &lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 16:36:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/loop-xml-attributes/m-p/232962#M194795</guid>
      <dc:creator>pchallauk</dc:creator>
      <dc:date>2017-07-11T16:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: loop xml attributes</title>
      <link>https://community.cloudera.com/t5/Support-Questions/loop-xml-attributes/m-p/232963#M194796</link>
      <description>&lt;P&gt;Excuse me &lt;A rel="user" href="https://community.cloudera.com/users/2119/pchallauk.html" nodeid="2119"&gt;@Pavan Challa&lt;/A&gt;, I should have looked at the related question more carefully.&lt;/P&gt;&lt;P&gt;So, what you'd like to do is looping through 'dataFlow' elements to find one which has 'filePattern' that matches with the name of incoming file? If so, that might be too much to do with XMLFileLookupService. I'd write a script with ExecuteScript that parses the XML file and do the matching.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 19:09:46 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/loop-xml-attributes/m-p/232963#M194796</guid>
      <dc:creator>kkawamura</dc:creator>
      <dc:date>2017-07-11T19:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: loop xml attributes</title>
      <link>https://community.cloudera.com/t5/Support-Questions/loop-xml-attributes/m-p/232964#M194797</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/2119/pchallauk.html" nodeid="2119"&gt;@Pavan Challa&lt;/A&gt;&lt;/P&gt;&lt;P&gt;If I understand your use case correctly, I think I have come up with a groovy script to do the job.&lt;/P&gt;&lt;P&gt;It loops through dataFlow elements, test if filePattern matches, then resolve path with ExpressionLanguage. Please check this Gist if it works for you:&lt;/P&gt;&lt;P&gt;&lt;A href="https://gist.github.com/ijokarumawak/a4ef40b49b45cecf3c43b56493683725" target="_blank"&gt;https://gist.github.com/ijokarumawak/a4ef40b49b45cecf3c43b56493683725&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I had to change filePattern to be Regular Expression&lt;/P&gt;&lt;PRE&gt;&amp;lt;filePattern&amp;gt;salary_*.gz&amp;lt;/filePattern&amp;gt;
/* Added a dot before the star */
&amp;lt;filePattern&amp;gt;salary_.*.gz&amp;lt;/filePattern&amp;gt;&lt;/PRE&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 20:02:34 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/loop-xml-attributes/m-p/232964#M194797</guid>
      <dc:creator>kkawamura</dc:creator>
      <dc:date>2017-07-11T20:02:34Z</dc:date>
    </item>
  </channel>
</rss>

