0

I have tried to get xml property and xml task, how can I loop the 2 or more files which are in fileset? I get a file list when I tried to get them in for loop so I can parse each xml property.

Test1.xml:

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>  

Test2.xml

<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
</CATALOG>

They are in same folder I get its file set and added in a list, get its list of file in that folder, then I tried to parse these xml file and find out what each xml file have in there an element tag:

<target name="findxmlParse" >
    <echo>${srcDir}/xmlfolder/</echo>
    <resourcecount property="countObject">
        <fileset  id="filesref" dir="${srcDir}/xmlfolder/">
         <include name="*.xml"/>
        </fileset>
    </resourcecount>
    <!-- <echo message="There are ${countObject} object in This Folder ${srcDir}/xmlfolder/"/> -->
     <property name="files" refid="filesref"/>
     <for list="${files}" delimiter=";" param="file" >
    <sequential>
        <!-- <echo message=" @{file} "/> -->
        <!-- this is  working  for only file not in list -->
        <!-- <xmlproperty file="${srcDir}/xmlfolder/${file}" collapseAttributes="true"  /> -->
           <xmlproperty file="${srcDir}/xmlfolder/@{file}" collapseAttributes="true"  />

        <echo >@{file}--${note.to} -- ${CATALOG.CD.TITLE}</echo>

    </sequential>
    </for>
</target>

How can I parse those files and extract its element property by those filelist in particular folder?

${srcDir} - local dir
nj2237
  • 1,220
  • 3
  • 21
  • 25

1 Answers1

0

You could use JAXB, which plays rather nice with ant:

  1. Extract schema (.xsd) for each xml that you’re parsing. Check it in.
  2. Use xjc to generate JAXB classes from the schema
  3. Write a custom ant task to invoke JAXB unmarshalling. Say <listTitles catalog=“${src.dir}/thecatalog.xml” />

Let me know if you need code samples, but I’m quite sure you’ll have more fun learning this stuff on your own.

Timir
  • 1,395
  • 8
  • 16