Eric'o'theque!
Saturday, February 04, 2006
Editing OPML using a quickly generated Microsoft InfoPath form

 

(Files to download noted at the end of this post.)

A while back, I was once again extolling to my team the virtues of blogs as a place to keep track of emerging technical and business trends. Oh, all the useful stuff that shows up on http://blogs.msdn.com/ ! Oh, the analysts giving their competitive insights into what Microsoft is and is not doing.

As a way to jump start people, I wanted to share my blog list. The easiest way to do that is to create an OPML file and send it out. I happen to have moved from NewsGator to Bloglines (thanks to OPML) and I decided I would export my current Bloglines subscriptions and send that file out so that people could import it into their newsreader of choice (even http://live.com/ !) and see all the great stuff I scan during the day.

But... I really didn't want to share the fact that I subscribe to Cute Overload. It provides the occasional "aw!" moment during the day that puts a smile on my face, but it's not something the old bearded manager geek should necessarily broadcast in their OPML attachment. So I wanted to edit my file before sending it out. I loaded the OPML XML up in notepad. Oh, no, it's all one big compressed stream of angelized XML. Damn, I thought. Now I have to go and find an XML pretty printer so that I can be sure I can read the whole thing and make sure that Cute Overload and Luann and Rose is Rose are all properly removed.

But wait. I need to edit XML. Hey... I happen to be on a team that makes an XML editor. How about if I try using my own product to whip up a quick form to edit my OPML?

So, here's what I did to quickly edit my OPML file with InfoPath. It was quick for me since I know the product reasonably well. If you have InfoPath installed and readily available, get used to it so that when you find yourself having to deal with XML just dying to be edited you can quickly whip up your own InfoPath form template and start jamming with it.

Create the InfoPath form: I started up InfoPath, told it I was designing a new form and that I was using my downloaded OPML file as an example of the XML. Look over at the data-source: that's the schema structure that InfoPath has inferred. Oh, how InfoPath eats XML for breakfast!

Create the layout: well, here's what you might be tempted to do: drag the opml root of the tree over and release and choose section with controls. Hey, that looks good! Well, not column lined up kind of good, but there are nicely named labels and text boxes for all of the controls. But, there's a problem if you just leave it with this: you don't get the recursive nature of the outline node.

In the data source task pane, expand the outline node. Notice that outline includes outline. We need to make sure that InfoPath generates the correct structure here and right now, it's only good for the first level of the schema (which, when you're designing something meant to be an outliner, doesn't get you too far). So, do the following:

Now, at this point, you are at a very basic, functional, OPML editor. It's not pretty. Things are not all lined up. But, you can now edit that OPML so that people don't know you like looking at little bunnies and ferrets and puppies.

Publish the form: in order to use the form template, you actually have to get it out of the designer and into a file that anyone can open. Choose File -> Publish and the publish wizard pops up. We're just going to publish this to c:\infopath\edit-opml.xsn, so choose the first option to publish to your computer, enter c:\infopath\edit-opml.xsn as the destination (of course, creating c:\infopath\ if you have to), and hit Next. Unless you're sharing this with people, just Next through the next screen and hit Finish. Now you have a checkbox to check before you press Close: open this form from its current location. Now press Close.

Alright. You've got a new blank OPML form. That's fine and all. Save this XML to something like blank.xml. We need to do one last thing before we can edit your OPML in InfoPath.

Make it an InfoPath form: Open blank.xml up in Notepad. Notice those processing-instructions up on top, the ones that start with <? and end with ?> ? We need the two that have mso in the name. They look something like:

<?mso-infoPathSolution solutionVersion="1.0.0.2" productVersion="11.0.6357" PIVersion="1.0.0.0" href="file:///C:\InfoPath\edit-opml.xsn" name="urn:schemas-microsoft-com:office:infopath:Edit-my-OPML-:" ?>
<?mso-application progid="InfoPath.Document"?>

Yeah, I know. Lovely. Well that's the secret sauce for making an XML file (a) an InfoPath file and (b) identify which InfoPath form is best suited for opening the XML up. Paste this into your OPML file after the XML declaration and save your OPML file - be sure it has an .xml extension.

Wait for it: double click on that file you just saved. It opens up in InfoPath ready to edit! Now you're cookin' with gas! Edit, add, use InfoPath edit-UI to your heart's content. Goodbye Cute Overload. My coworkers will have to find you themselves. Save and share.

After-thoughts:

XSD: Ideally, you would have designed off of a real XSD for OPML. Looking at the OPML spec site, I see there's a reference to a DTD but I don't see any XSD. I think, like RSS, OPML has been a bit flexible in what it allows. So even if you find an XSD, you might end up having it not like whatever OPML you try to validate against it.

So thank goodness that InfoPath can infer an XSD. Just be sure you have the biggest, meanest XML instance to start designing against.

Design: if I was going to share this or use this solution over and over again, I would go back and spend 15 minutes in the designer making it look better. I like labels and controls to line up, so I would go under the auto-generated control and insert a two-column layout table, dragging the label into the first column and the control into the second, making sure the control was as wide as possible. See below for my 15 minute clean-up results.

Publish to share: if you want to share this with more people, publish it to a public area. A SharePoint site. Maybe a network share. Or a web server. Just realize that that the processing-instruction secret sauce is based on where you published it.

Additional views: if I was editing a bunch of OPML and then wanted to paste them into a blog-roll like web page part, I'd create a second view of non-editable output and use that to paste. But really the best answer here is just an XSLT you can apply to the final OPML.



Files you can download:



Updated: see if I can manage to get Technorati tags to actually work...

 
Comments:
You forgot to mention that whoever doesn't have Infopath, can just unzip the xsn file and pry out the valid xsd ;)
 
The infered xsd isn't valid after all. It might be enough to create OPMLs but it certainly isn't enough to validate anything where the outline element recursively contains itself > 2 times.
I have uploaded a proper XSD and the generated wrapper classes here http://cid-40a42b28e3a94bab.skydrive.live.com/browse.aspx/OPML%20studies .
 
Post a Comment

Links to this post:

Create a Link



<< Home
Eric Richards' place of techno (as in technology) happiness, rants, and corporate love. I work in Microsoft Office as a development lead.

My Photo
Name: Eric Richards
Location: Redmond, Washington, United States

Non-technical stuff going on with EricRi in the Northwest.

email: Eric_Richards at ericri dot com

Lots More About Eric.

Eric-isms
Archives
May 2005
August 2005
November 2005
January 2006
February 2006
March 2006
April 2006
May 2006
June 2006
July 2006
August 2006
September 2006
October 2006
November 2006
December 2006
January 2007
February 2007
March 2007
April 2007
May 2007
June 2007
July 2007
August 2007
September 2007
October 2007
November 2007
December 2007
January 2008
February 2008
March 2008

Disclaimer

Disclaimer: The postings (and comments) here represent personal point of views and in no way represent the point of view or official opinions of my employer (Microsoft Corporation). The postings here are provided "AS IS" with no warranties, and confers no rights. And if you're reading this blog, you're not only incredibly discerning, you're also knee-weakening good looking.


More blogs about Eric Richards.

Powered by Blogger