Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I need to design an XML file that would map fields and field values of two objects, say A and B. Fields are mapped one-to-one and values - many-to-one.

So far I could think of this design:

<obj_mapping>
    <field>
        <A_field>A_field_name</A_field>
        <B_field>B_field_name</B_field>
        <value_mapping>
            <A_value name="A_value">
                <B_value>B_value_1<B_value>
                <B_value>B_value_2<B_value>
                ...
            </A_value>
            ...
        </value_mapping>
    </field>
    ...
</obj_mapping>

Do you feel like this is good enough?

share|improve this question

closed as off-topic by Malachi, Phrancis, Kid Diamond, Mat's Mug, RubberDuck Sep 5 at 19:13

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Questions must involve real code that you own or maintain. Questions seeking an explanation of someone else's code are off-topic. Pseudocode, hypothetical code, or stub code should be replaced by a concrete example." – Kid Diamond, Mat's Mug, RubberDuck
  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. Such questions may be suitable for Stack Overflow or Programmers. After the question has been edited to contain working code, we will consider reopening it." – Malachi, Phrancis
If this question can be reworded to fit the rules in the help center, please edit the question.

    
any reason you have name="A_value"? –  ArsenMkrt Dec 27 '12 at 13:20
    
Any reason for keeping A_field and A_value in separate branches? Maybe simple <A_values name="A_field_name"><A_value name="A_value"><B_values name="B_field_name"><B_value>B_value_1</B_value><B_value>B_value_2</B_value></B_‌​values></A_value>? –  ony Dec 27 '12 at 13:22
    
This code is untested and not implemented. –  Malachi Sep 5 at 18:39
2  
I'm sorry but we cannot review pseudo-code. –  Phrancis Sep 5 at 18:52

1 Answer 1

Some ideas:

  • It maybe a matter of taste, but using snake_case for tag names seems strange to me. camelCase or dash-separated would be better.

  • Tag names like A_field and B_field are not great, especially when you use them to indicate field names. srcName and dstName would be better, to clarify that they are about names, and the source and destination.

  • In the description you wrote that values should be many-to-one, but then in value_mapping you have a single A_value and multiple B_values. Intuitively, I would imagine the mapping goes from A to B, but your sample looks like B to A.

  • In <A_value name="A_value"> you use the name attribute to indicate a value. A value attribute would be more natural.

How about something like this:

<objMapping>
    <field>
        <srcName>ou</srcName>
        <dstName>OrganizationUnit</dstName>
        <valuesMapping>
            <dstValue value="IT">
                <srcValue>Development</srcValue>
                <srcValue>QA</srcValue>
                <srcValue>Support</srcValue>
            </dstValue>
        </valuesMapping>
    </field>
</objMapping>

I didn't change the overall structure of the tree of nodes. It seems to make sense to me. But you would have to test it and see if it's really ergonomic or not.

Finally, you asked for a many-to-one mapping of the values, so just beware that the mapping will be one-way, non-reversible.

share|improve this answer

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