can you validate xsd against xml in vs 2010? - visual-studio-2010

How do I validate an xml document against an xsd in Visual Studio 2010?
Thanks.

Open you XML file in VS2010; in the Properties tool window (F4) there is a Schemas property. List the XSD you want in there. Once done, the errors/warnings will show up in the Error List tool window.

There are a few things you need. First the XML Document must be associated with the Schema:
<XmlDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\Code\Schema.xsd">
</XmlDocument>
Now you need to have that Schema XSD Added into your Project. Now when you open the XML Document you should get intellisence and errors / warnings shown as you would errors in your normal C#/VB/etc/ code.

Related

Using a DLL I've created in another VS2010 project doesn't show the intellisense tooltips

I've created a DLL to a project in Visual Studio 2010.
I'm using this DLL in another project. Using the functions is completely possible - but I can't see any tooltip.
In addition - if I'm in the same project the tooltips can be seen.
I've read some issues about using the XML file with the name of the DLL in the 2nd project, but I'm afraid I don't have any XML file (as far as I see...).
I'll appreciate your help!
Lior
In the project settings of your DLL you can specify that a XML file will be created each time the assembly is build. Thi setting is located on the "Build" tab, region "Output" and is called "XML documentation file". Mark the checkbox in front and the xml file will be created.
When you use the dll in another project you have to copy the xml file along with the assembly file to have the IntelliSense information in place.

"Add Service Reference..." to xsd

I can create a service reference in Visual Studio 2010 to an xsd. That reference downloads all the linked xsd files. However, I have 2 problems I'd like to see if there are solutions:
The URL for each xsd actually ends in .gx (e.g., http://mycompany.com/Schema1.gx). When Visual Studio imports the files, it renames them to .xsd, but in the xsd:import node, it keeps the original reference name with .gx, so my reference, once it's in Visual Studio is "not found or invalid"
for some of the xsd:import statements, the path to the referred-to .gx file is in another directory (e.g., schemaLocation="subDirectory1/Schema1.gx"). However, when they're imported, all xsd files are in the same directory in Visual Studio, but again, the xsd:import node is not modified to reflect the flatter structure.
Is there a solution to import these xsds in a valid way?
It is most likely a bug - the svcutil doesn't "refactor" the schemas. If you want a tool that handles this kind of work and more like it, this XML Schema refactoring tool should help. Download, install and create a new XML Schema Refactoring file (.xsr); add a new XML Schema collection; right click on the version 1.0, select [Import Schema Files...] command and follow the prompts. It can "slurp" online schemas, including ones referenced from, or embedded into, WSDL files, etc.

What does "Unauthorized zone" mean when browsing xsd files with Visual Studio 2010?

When I open up an xsd file that includes other xsd files, all of the included files are added to a section called "Unauthorized zone". Visual Studio highlights the xs:include element and gives the following error when trying to resolve the schemaLocation attribute:
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
I've read the following blog post, but I'm not familiar enough with xsd yet to fully understand it.
Can anyone explain why this is happening or point me to a good resource that can help?
[Edit]
All of the xsd files that are to be included are in the Visual Studio project.
For me it worked after going to the properties of the XSD file and clicking on Unblock. i got this answer from How do I modify my settings to allow VS2010 to load 3rd party XSD files from the "Unauthorized Zone"?
Visual Studio caches XSD schemas at %VsInstallDir%\xml\Schemas with Target Namespace attribute (url of schema file) when you add them to your editor.
Blog post says that
The inclusion of Local.xsd in the “Unauthorized Zone” and the warnings in the error pane about not being able to resolve the schema location are an indication to the end user that the schema they were visiting attempted to bring in a schema from a zone that it is not authorized to access.
Reason the IO Permission error shows itself is your machine has no authority to download external xsd file(s) from the location.So there is no cache that Visual Studio might validate your other xsd files.
You should check your networking options so you may download those xsd files.While you can it means you have access to that location,so Visual Studio can cache them.If you're sure that you have access,you may also download those xsd files and put them Visual Studio's default schema location and indeed add them in editor.
Also check about cache here
Hope this helps
Myra
Need to do 2 things:
Unblock the xsd file, in windows do right click in properties a click unblock.
Go to visual studio, options, tools, text editor, xml, and check downloads dtd and schemas.
These warnings will disappear when you run Visual studio as administrator.

Add an XML schema to Visual Studio

I want Intellisense support when writing App.config sections or XML configuration files for components like NHibernate, log4net, or Unity. What options do I have to get Visual Studio to find these files and load Intellisense?
(Assume we have the schema file.)
Yes it is possible to do this. You need to associate the schema with the document and the XML editor will then provide intellisense. The following links go over how to achieve this
http://msdn.microsoft.com/en-us/library/ms255811.aspx
http://msdn.microsoft.com/en-us/library/ms255815.aspx
Open your config file, under the properties window for your config file there is a section called 'Schemas', add your schema there.

How to export and import an XSD file in Visual Studio?

How do i export and import an XSD in visual studio? I simply tried to do a copy-and-paste an xsd file into a new project and VS2008 automatically created some wrapper classes for it. When i tried to add a query to a table in VS, I get an error that the connection strings are broken. I slightly fixed that by inserting the proper connection string to app.config but i still get errors related to the connection string.
My question is not how to fix this connection string but how do i just properly export and import connection string? is there a wizard I can use? Thanks
Update #2
This XSD file that I'm using was created by using VS studio by dragging and dropping tables using this tutorial http://www.asp.net/learn/data-access/tutorial-01-cs.aspx. I copied this XSD file and pasted it into a new project and VS automatically generated code for it, which in this case a "typed dataset". In this new project, when i tried to add a query to a table in the XSD file (using the tutorial I mentioned before), I got an error stating that the connection string 'xxxxxxxxx' does not exist (im paraphrasing). This 'xxxxxxxxx' connection string exists only in the project where i copied the XSD file from and not in the new project. Therefore, this xsd contains information dependent on the web.config, specifically it's connection strings. So coping and pasting this XSD file does not work. I was hoping there was a wizard export tool that would strip away the depending information (ie: connection string) and its associated settings so that i could properly add it to another project and add a query to a table without errors. I hope that makes sense...
This does not work. The problem is that adding an existing dataset to a project only adds it as an xsd i.e. Visual Studio is thinking xml schema not dataset. This is true even in VS 2015. In order to make this work, after you add the existing xsd file you must edit the project file with gvim or notepad and add the following lines:
Add in the compile section:
<Compile Include="MyDataSet.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>MyDataSet.xsd</DependentUpon>
</Compile>
Look for the ItemGroup tag that has
<None Include="MyDataSet.xsd"/>
Change that line to look like the following and add a couple more Done tabs just so:
<None Include="MyDataSet.xsd">
<Generator>MSDataSetGenerator</Generator>
<LastGenOutput>MyDataSet.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</None>
<None Include="MyDataSet.xss">
<DependentUpon>MyDataSet.xsd</DependentUpon>
</None>
<None Include="MyDataSet.xsc">
<DependentUpon>MyDataSet.xsd</DependentUpon>
</None>
Save the file and reload the Visual Studio project. You are almost done. Right click on the xsd file and select run custom tool. Now you can build and you should be ok.
What do you want to do with your XSD??
By default, Visual Studio will created a "typed dataset" based on your XSD. You can use that to query your database table and update it if needed. Is that what you want?
If not: what do you want to do with your XSD inside Visual Studio then??
You can easily just add an existing XSD on disk to your Visual Studio project by doing a "Add Existing Item" and then picking that file. There's no separate "import / export" functionality, really.
If you only want to use your XSD for documentation / information purposes, click on the file and in its properties window, set its "Build Action" to "None" or "Embedded Resource".
Marc

Resources