WordML templating with XML Schema and OpenXML SDK - asp.net

I'm trying to use a docx read in via the OpenXML SDK as template in a .Net web app for form letters (essentially). I have a docx with the formatting I want, marked up with XML Schema tags defined from a xsd (whatever they're called, the help is exceedingly useless on this).
The only thing similar I found on Google was what seemed to be replacing the CustomXmlBlock elements with text elements with the desired data. This seems... messy and fragile.
I also have the added complication that some of the data is hierarchical, with elements for sections, and then items in that section. This would seem to completely break the above method.
So, can someone point me in the right direction for doing this, or suggest a better way to handle templating form letters?

There are a number of choices:
What you're doing, XSD Schema mapping. This was introduced in Word 2003. It was really only truly active in that version of Word as when Word 2007 came out, the preferred new method of forms became #2.
Content Controls. More on this below.
Tried and true are Bookmarks. If you're interested, there is an article here.
For Content Controls 1, the concept is simple: wrap your content controls in the hierarchy needed. That is to say, for example, have a Date Picker Content Control and a Rich Text Content Control and then group them. Then inside the Rich Text Content Control, place a Combo Box Content Control. Eric White has written a great starter article on this at retrieving content from inside of Content Controls at Processing all Content Parts in an Open XML WordprocessingML Document. This article is a much more comprehensive introduction to Content Controls in it's links Using Open XML WordprocessingML Documents as Data Sources.
More links on Content Controls:
Brian Jones' site has a lot of great articles. I believe these were his first: The Easy Way to Assemble Multiple Word Documents and Create a rich Word document based on your own custom XML (without the need for XSLT).
The Word Content Control Toolkit. Probably the best tool around for working with Content Controls.
Visual How To Content. Many articles here deal with Content Controls.
1 To work with Content Controls manually in the Word client, enable the "Developer" Ribbon from Options and then insert Content Controls and set their properties from the left-hand section of the Controls group in the Developer Ribbon.

Related

Can Sitecore templates be used to store SQL Queries or JavaScript

We are building a Page with dynamic functionality using ASP.NET + Sitecore 7.0.
Is it practical and appropriate use Sitecore templates for:
SQL Stored Procedure Name to be invoked
JavaScript to be invoked
ColumnNames to be used etc (related to coding customization)
Or should these configuration properties remain inside the ASP.NET Project itself?
What is the primary purpose of Data Templates in Sitecore?
Are they for developer customization or customer-level customization?
The purpose of a data template in Sitecore is to define the set of fields for content items which inherit from that template. - Think of a data template as a class and the content items (pages) as instances of that class.
Templates are usually used to define the user-editable content of pages within a site, that being said you can have items to store information which is not managed by regular content editors. The question is where do you draw the line between things which should be put into Sitecore and things which should be a part of the solution. My advice is only put things in Sitecore if they need to be there. If you have to have the ability for editors or admins to configure those settings/properties.
I would say that putting SQL/ColumnNames is probably a bad idea unless you are building some sort of report builder interface in which case it may be essential?
Likewise with placing JavaScript into Sitecore; this can be OK in moderation (e.g. snippets of analytics code which content editors may want control over?). If you're placing whole libraries of JavaScript into Sitecore, you're probably doing it wrong.
One final point to note is findability/re-factorability of code: if you have code spread between Sitecore and your solution, it can make it very difficult to maintain as it is difficult to get a complete overview of code involved.

Does providing PDF content when it could be HTML break accessibility?

I want to provide some very simple content to the user that describes how to use a web form.
This text could just as easily be written in HTML, however, convention among the content writers is to write all help text in Word, convert it to PDF, and then put a link to the PDF at the top of the web application.
Assuming that the PDFs are tagged and/or 508 compliant, does this practice present any accessibility concerns?
There are two issues posed with your question:
(1) PDF when it could be HTML
This requires the user to have software that reads PDF format.
This requires the PDF to be tagged and made accessible.
This interferes with usability and is problematic for some users, especially on mobile where the focus switch to a different (PDF reader) application looses focus on your web page or web browser.
(2) "breaking" accessibility
The accessibility of your web content is evaluated on its own merits: you certainly can have an accessible PDF but if your reasoning is your HTML does not need to be accessible because of that, you are not accessible and fail your end-users.
There is also a hidden use-case for accessibility or usability you might not consider: web crawlers and indexing. Users rely on web searching to find content and your PDF is not indexed to map to your web page content in most search engines, so users will not find the help they need.
Most reasonable people involved with Section 508 would likely agree it is not accessible, as it fails 1194.22(n): When electronic forms are designed to be completed on-line, the form shall allow people using assistive technology to access the information, field elements, and functionality required for completion and submission of the form, including all directions and cues.
ยง1194.22 Web-based intranet and internet information and applications
It is possible to convert Word content to HTML, and you are always highly encouraged to write the content as web content, because there are sometimes issues we simply accessing, and opening PDFs depending on the device they are using.
But to answer your question: no, as long as your PDF is accessible. I'd suggest putting it through something like the accessibility audit tool if you have Adobe Acrobat. If you don't, you might give content creators a simple check list, such as:
does your image have alt text if needed? (consider a decision tree/flowchart, example)
are your headings marked properly using the built-in styles?
are your tables formatted correctly? also tables are not used for layout
You'll probably notice these are typical guidelines when writing web content, but also apply to documents (Word, pdf, etc.).
WCAG has a list of PDF Techniques that you also want to check, but generally if you make sure that everything is tagged/styled/marked properly in Word, it should save to PDF with the correct tags and such.

Is there any existing web control that permits the entry of both text and images in the manner of

I want to know is if there is any textbox-type web control out there that can approximate Word for simply WYSIWYG editing?
I am NOT talking about so-called HTML or Rich Text controls. (In fact I'd prefer if the users didn't play with colors and font sizes.)
What I need is a control that allows a non-technical user to intutively copy images and paste them in without having to fiddle with HTML tags.
Is this even possible in current web technology?
take a look at the HtmlEditorExtender, from asp.net ajax controls can be very simple, and easy to add to your asp.net project.
The full project: http://ajaxcontroltoolkit.codeplex.com/
You can use CKEditor. You can then customize it so that the options you don't want to show up (color, font size, html editing) don't show up. Otherwise there is no built-in .net control to accomplish this.

OpenXML: Creating reusable Content Controls with binding

I need to attach specific XML to a word document so the elements will show up in the right places. This I can do with OpenXML SDK.
The thing is I want too be able to define the Content Controls already bounded in some sort of template so other people can create the real document template the xml will be attached to. Ok not sure people will undestand what I mean so I will explain further.
There may be many different document templates that will use the same XML data and so the same Content Controls. It's up to someone else to create the document.
Scenario: Some dude that's not a programmer needs to create a new form for the usual info because of some changes ( new layout or somehting ). This has nothing to do with the XML info, that stays the same.
Optimal solution for "some dude" would be to create the document in Word and drag the Content Controls into place ( or some solution similiar). Then when the XML gets added to the document there is no problem as the Content Controls are pre-binded.
Now there are a few points here:
1) Can Content Controls be pre-binded? If there is no XML at the path won't it just stay empty without problems?
2) Will binding Content Controls to CustomXML's like this still work in future versions of Word because of the i4i lawsuit?
3) Is there perhaps another optimal solution better then this?
Thanks in advance.
EDIT:
To be more clear. I wan't to create Content Controls that would have some name to identify them and a databound xpath. However at that moment there is nothing at the path.
Another user comes in and creates a form, decides the layout on so on, and then adds the Content Controls into the places he wants the info to be.
Later on the info for item X is requested using the new form. So a copy of that form will be taken and the CustomXML will be added into the Docx file. Now because the XML shchema was known beforehand and used when deciding the paths for the CC's this XML data will be bound to the Content Controls.
One great option would be to use VSTO (Visual Studio for Office) to build a set of document templates that have your prebinding code attached. These two articles provide a good start into looking into this type of a solution:
Creating a Template By Using Content
Controls
Binding Content Controls to Custom
XML Parts
There are two threads that discuss some details of this: 1 and 2.
One of the benefits about using VSTO is that you can hook the Content Control events: Content Control Event Model in Word 2007.
If VSTO is not an option, you can always look at Add Custom XML Parts to Documents Without Starting Microsoft Office.
This should be very straightforward. Custom controls are not impacted by the i4i lawsuit and you can name them using the tag property in each control (warning - it is limited to 64 characters).

Rich-Text Editing of Word Documents on the Web via ASP.NET

My users upload Word 2007 documents to our site and I'd like to load them into a rich edit control of some kind so the users can make modifications/ comment, etc.
What mechanisms are available to:
load the Word document via ASP.NET, and
parse/format/display the document in a rich editing control?
Also, what kinds of rich editing controls are best to use in this circumstance?
I believe that telerik's Rad Editor supports the ability to paste from word.
From the site:
Seven Ways for Pasting from Word
Telerik ASP.NET Editor offers a number of features that help the user paste formatted content from Microsoft Word and other applications, and apply different types of format stripping:
Strip Word-formatting on paste Strip
Word-formatting on paste (cleaning fonts and sizes)
Forced format
stripping on Paste Word Content in
Clipboard Interception Strip
Word-formatting after paste Paste
plain text Paste as HTML
Here is the demo
Try TEEdit. It is great for doc and docx files. Allows for save and open buttons too...
For display Word document, this is an intresting project using combination of Silverlight and OpenXML, worth having a look
http://openxmldeveloper.org/articles/TextGlow.aspx
For editing, it will be more complex. Currently there are editors out there like CKEditor, TinyMCE, but they are mainly used for editing rich text but not as natural when it comes to handling document like word that has very rich page layout and device bound are support.

Resources