locked
Add XSD to ItemTemplate RRS feed

  • Question

  • I've created an ItemTemplate which works as expected but what i'd like to do is set the Schema to a custom XSD

    Ive seen some things about registering the namespace so that VS knows automatically and reads from the cache but i'd prefer to have this all isolated to the ItemTemplate (zip file) itself if possible, can this be done?

    I dug around the TemplateContent but none of that seemed to do what i wanted. 

    I did find a few posts on here but none of them seemed to be what I was looking for. Most of what I have seen has been partial answers (or just not enough detail for me, since im really new to this).

    Thanks,

    Justin

    Friday, September 5, 2014 8:42 PM

Answers

  • Sorry, no, what i mean is i've created an ItemTemplate project that is basically for an XML file. I'd like to provide an XSD to the end user to help them create the xml files easier.

    I've managed to find some older references (vs2010) saying its not currently possible and planed for newer versions, but I havent see anything in reference to 2013, I assume it cant be done without doing what you suggested with the wizard and extract and dump it in manually.

    Based on your second link i might be able to add the XSD as part of the new item and then modify the XML template to include something like 

    xsi:noNamespaceSchemaLocation="myCustom.xsd"

    • Marked as answer by Caillen Tuesday, September 16, 2014 9:42 AM
    Wednesday, September 10, 2014 6:58 PM
  • I prefer this method too. Create a custom XML and add the schema location in it. Include the schema file into the Item Template so that when you deploy this Item Template, the schema file will be deployed as well.

    About how to create a mult-files Item Template, please check this MSDN document:

    http://msdn.microsoft.com/en-us/library/ms247115.aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Caillen Thursday, September 11, 2014 4:09 AM
    • Marked as answer by Caillen Tuesday, September 16, 2014 9:42 AM
    Thursday, September 11, 2014 3:03 AM

All replies

  • Hi Justin,

    Do you mean you want to valid the .vstemplate xml file with you own XSD file?

    There's one approach I can think of, to programmatically validate the .vstemplate file in VSIX project, since you don't want to pollute the original ItemTemplate zip file.

    When you deploy an ItemTemplate into the production VS IDE, you need to create a VSIX project along with the ItemTemplate project. With VSIX project you could create some custom wizard. That means you can do something in the custom wizard in C# or VB.NET language. What you need to do is to create a class, implement the IWizard interface, and do some actions in it. Here's a good article by Ed Dore which is talking about this:

    Creating a VSIX Deployable Project (or Item) Template with Custom Wizard Support

    In the custom wizard class, you could programmatically get the original ItemTemplate zip file, extract the  .vstemplate xml file and use the specified XSD to validate this XML file. If it's not what you want, just replace the .vstemplate xml file with the modified one.

    Here's a KB article talking about how to validate XML file with XSD:

    How To  Validate an XML Document by Using DTD, XDR, or XSD in Visual C# .NET

    To extract zip file, ZipFile class in .net framework 4.5 will help, for earlier .net frameworks, you may need to use some opensource libraries to help you, e.g. SharpZip.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 10, 2014 6:45 PM
  • Sorry, no, what i mean is i've created an ItemTemplate project that is basically for an XML file. I'd like to provide an XSD to the end user to help them create the xml files easier.

    I've managed to find some older references (vs2010) saying its not currently possible and planed for newer versions, but I havent see anything in reference to 2013, I assume it cant be done without doing what you suggested with the wizard and extract and dump it in manually.

    Based on your second link i might be able to add the XSD as part of the new item and then modify the XML template to include something like 

    xsi:noNamespaceSchemaLocation="myCustom.xsd"

    • Marked as answer by Caillen Tuesday, September 16, 2014 9:42 AM
    Wednesday, September 10, 2014 6:58 PM
  • I prefer this method too. Create a custom XML and add the schema location in it. Include the schema file into the Item Template so that when you deploy this Item Template, the schema file will be deployed as well.

    About how to create a mult-files Item Template, please check this MSDN document:

    http://msdn.microsoft.com/en-us/library/ms247115.aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Caillen Thursday, September 11, 2014 4:09 AM
    • Marked as answer by Caillen Tuesday, September 16, 2014 9:42 AM
    Thursday, September 11, 2014 3:03 AM
  • So, its forcing me to use the TargetFileName and $fileinputname$ which means each file added would have a copy of the schema.. i guess it could be worse, but ideally i'd only want one.

    Im considering making it part of the Project templates and then just making an assumption as to where the xsd will be located in the xml files. This is a tad unsafe and not ideal, but it reduces duplicates and a mess.

    Since this project is more than just templates i might add some code to push it to the global schema cache... 

    Thoughts?

    Tuesday, September 16, 2014 7:28 PM