1

I want to create a XML file in which I want to use a node with subnodes inside in other nodes(REUSABLE).

If I am using this node again and again, my XML will be too long. Is there any way to write node only once and refer (or link) it whereever necessary?

Amol
  • 133
  • 2
  • 11
  • Actually I want to use a node which contains a subnode (information) and that node I want to refer whereever necessary (as a reference) I am also thinking wether can I use XSD? – Amol Sep 18 '15 at 12:52

1 Answers1

0

I may have a suggestion, but it will depend on how you use the xml file and who who takes care of it.

You could make a special(special to you) tag that will mean something for you when you parse the xml.

For example:

<notes>
    <note>
        <to>Person1</to>
        <myAddress></myAddress>
        <heading>Reminder</heading>
        <body>Don't forget to do stuff</body>
    </note>
    <note>
        <to>Person2</to>
        <myAddress></myAddress>
        <heading>Assignment</heading>
        <body>You need to do stuff!</body>
    </note>
    ....
</notes>

<myAddressDef>
    <name>Me</name>
    <position>Boss</position>  <!-- Because why not :) -->
    ....
</myAddressDef>

Every time you encounter myAddress tag, you will know that it's „defined” under the myAddressDef tag and get the content from there.

Cristian Marian
  • 750
  • 1
  • 8
  • 18
  • Thanks If I need the following same node in different nodes(multiple time), can I use ref="something" ? Person1 Reminder Don't forget to do stuff If multiple times I am using the same node, it will be duplication So how to refer a node it is still a problem – Amol Oct 05 '15 at 06:00
  • @Amol I don't quite understand what you mean. Being the one who parses the xml, you can do pretty much anything you want. Maybe if you post an example of what you are trying to achieve, thing will get more clear. – Cristian Marian Oct 05 '15 at 08:13
  • @Amol , Do you want to reuse the book tag with another values? If so, the thing to do is use them as they are; else, the whole meaning of xml is lost and a simple csv file would do the trick for less space. – Cristian Marian Oct 05 '15 at 08:23
  • yes, exactly same, place a common tag or node which is same and present in other nodes and whenever required, just refer it. – Amol Oct 05 '15 at 08:31
  • Well, for that, I really like [this answer](http://stackoverflow.com/a/5127928/4153931). It's easy to use and it doesn't require as much work as my approach. – Cristian Marian Oct 05 '15 at 08:40
  • Thanks for the answer Is there any example for including the NODE? – Amol Oct 05 '15 at 09:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/91372/discussion-between-cristian-marian-and-amol). – Cristian Marian Oct 05 '15 at 09:38
  • Can you please tell me its link again? – Amol Oct 05 '15 at 10:06
  • It's the accepted answer from this question: http://stackoverflow.com/questions/5121052/can-we-import-xml-file-into-another-xml-file – Cristian Marian Oct 05 '15 at 10:08