Maintaining XSD files in VS2010


Having more-or-less painlessly migrated across to my SSD drive (which is more than can be said for the one I use at work, which randomly wiped itself – even down to the partition itself – after I moved desk last Friday), it’s back to VS2010 stuff.

I had to do some work with XSD files lately in VS2010, and, having sort of suffered through using them in 2008, was pleasantly surprised with the direction that they’ve chosen to go in VS2010. So, if you’re unlucky enough to be working on an XSD files, read on to see if VS2010 will make it any less painful.

Getting started

The main view that you get when you open up an XSD file is a big white page with some options and statistics on your XSD file: –

image

Note that the “add” links don’t add a new element etc. to the schema – they add that selection to the “workspace”, which is the set of entities in your schema that you are “working with” for viewing – confusing.

Editing XSD files

The biggest change is that there is no editable designer surface any more in VS – all your editing (at least as far as I could find) of schemas must be done in the XML Editor. You get intellisense at least though, so it’s not that bad, and you can actually blitz through some tedious authoring relatively quickly. I’d like to see some support for code snippets, though.

image

You get real-time error checking of your schema – although I think that you got this in VS2008 so this is nothing new.

Viewing XSD files

You now get a “class view” of your entire schema, but with amended icons for XSD schema, called the XML Schema Explorer: –

image

Notice how the two types (Department and Employee) use the same Class icon as the Class Explorer etc., whereas the instance (element) – company – shows as an element icon. Role is an enumeration, but sadly this view does not show the available options of the enumeration – shame. One other nice thing is that you can search through the entire tree and do various sorting (name, type, document order etc.).

There’s also the Graph View which is supposed to show the relationship between selected nodes in your workspace:

image

I must’ve misunderstood this one, but I don’t see really what this view does – you drag items from the explorer view on the surface and it puts them there – big deal. I don’t see any relationship lines or stuff like that, so it seems kind of pointless. One nice thing you can do is select any element (e.g. company) and generate a sample XML document from it – quite handy.

However, there is one other view left – Content Model View – which is very nice. It’s an interactive map of your entities and types, allowing you to drill in to the tree but in a non-tree view(!). Let’s say we are viewing the “company” element (see in the explorer above). We would start with this: –

image

If you drill into it, you then get this: –

image

Drilling down again: –

image

And finally: –

image

This is actually a very powerful tool – the viewer handles all sorts, included attribute groups, cardinality etc. – very handy. Having the XSD editor and this view side-by-side makes it easy to both edit your schema and see the impact immediately.

Advertisements

2 thoughts on “Maintaining XSD files in VS2010

  1. How would you use this to create classes from the xsd files so you could create xml files from the classes? There is a state agency I have to send xml files to and they keep changing their xsd files.

    Thanks,

    Brandon

    1. As far as I know there is nothing in the XSD designer etc. that supports mapping of objects into XML files. You still have the existing tools such as XML serialization with e.g. attributes on your object model, but in your case, to remain flexible and not have to modify your domain model every time their XSD changes, you could probably just use Linq to XML to do the mapping and then validate the generated XML against the XSD that you’ve been provided.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s