1

I want to run a c++ program to process a lot of data from different xml files and output results. I run the program once per file and potentially have around 50 different files.

The trouble is each xml file has different naming convention for the nodes, for example:

A.xml

<entry>
    <id><![CDATA[9]]></id>
    <description><![CDATA[Dolce 27 Speed]]></description>
 </entry>

B.xml

<item>
    <uuiid><![CDATA[9]]></uuid>
    <content><![CDATA[Dolce 27 Speed]]></content>
 </item>

What is the appropriate way to define these mappings, so when I run the program the software knows what data is in what tags, so I can store the id, description etc together no matter what the input tags are.

Ideas I have so far are:

A) Start the program with flags (in the real program there will be 10 mappings so could get messy), I.e ./main --id uuid --description content

B) Put them in a map and refer to that at start up (any suggestions on how to do the map would be great), I.e ./main --map example1

C) None of the above

  • 1
    I would think (but let's wait for an answer by someone who knows definitely) that the best thing to do would be to employ something like Xalan or Xtrans to implement an intermediate XML transformation step, so that your software needs to know only one naming convention. The ability to perform such transformations is one of the major reasons why XML was invented in the first place. – Mike Nakis Apr 19 '15 at 7:54
  • @MikeNakis Its a great idea and one I have considered, I was just concerned with memory and processing time with that approach – Jimmy Apr 19 '15 at 7:58
  • 1
    Processing time will probably suffer, but it should only be by a constant factor, (you should be able to find a tool that works as a filter,) and then it should be noted that if performance is of any concern whatsoever, then XML was probably not the best choice in the first place. – Mike Nakis Apr 19 '15 at 8:03
  • 1
    Yes. Essentially you would code one minimal map somewhere, telling the XSLT processor how each of the original files should be transformed. – Mike Nakis Apr 19 '15 at 8:43
  • 1
    Since nobody has answered so far, I turned my initial comment into an answer. This will bump this question to the top, so it will be noticed by more people today, Monday. – Mike Nakis Apr 20 '15 at 10:01
2

I would think that the best thing to do would be to employ a tool like Xalan or Xtrans or any other XSLT processor to implement an intermediate XML transformation step, so that your software needs to know only one naming convention.

The ability to perform such transformations is one of the major reasons why XML was invented in the first place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.