Is there a way to insert one piece of code into another?

Suppose I have

  • fragment A
  • fragment B
    where fragment A contains fragment B n times with n> 1.

Right now I have copied the contents of fragment B to fragment A. This has the disadvantage that whenever I change fragment B, I have to additionally change fragment A. So my question is, is there some kind of statement for pasting one fragment in another?
eg
<externalsnippet src=".\snippetB.snippet" />
or something similar.

+6
xml visual-studio-2008 visual-studio code-snippets embed
source share
1 answer

You can use an external processed shared object to declare an object reference for fragment B, and then use it n times inside fragment A.

When fragment A is analyzed, entity references will be expanded, and the content from fragment B will be included in every place where the object was used.

For example, suppose you have a snipppetB.xml file:

 <snippetB> <foo>Content goes here</foo> </snippetB> 

And the file for fragment A declared an object called snippetB , referencing snippetB.xml, and used it four times:

 <!DOCTYPE snippetA [ <!ENTITY snippetB SYSTEM "./snippetB.xml"> ]> <snippetA> <a>&snippetB;</a> <b>&snippetB;</b> <c>&snippetB;</c> <d>&snippetB;</d> </snippetA> 

When parsing snippetA.xml, the XML content will look like this:

  <snippetA> <a> <snippetB> <foo>Content goes here</foo> </snippetB> </a> <b> <snippetB> <foo>Content goes here</foo> </snippetB> </b> <c> <snippetB> <foo>Content goes here</foo> </snippetB> </c> <d> <snippetB> <foo>Content goes here</foo> </snippetB> </d> </snippetA> 
+1
source share

All Articles