XML Mapping and Protection
By the Syncfusion DevTutorials team · Last updated
Link content controls to XML data, restrict editing, make documents read-only, and protect forms, then build a registration form in the Chapter 9 project.
After you finish a document, you may want to stop people from changing it by accident. For example, you might share a contract that should stay unchanged or a form where people should only fill in the answer fields. In this lesson, you'll learn how XML mapping connects document fields to data, how to limit editing, and how to protect a form. At the end, you'll build and protect a registration form in the Chapter 9 project.
Open the Word sandbox and follow along. You can practise the protection features in the sandbox. XML mapping is different: the sandbox doesn't include the XML Mapping Pane, so that part needs Microsoft Word.
XML mapping pane
Some organizations store information such as customer names, order numbers, and dates in other systems. XML is a way to organize data as text. Here is a small example:
Customer data in XML
<customer>
<name>Amina Otieno</name>
<city>Nairobi</city>
</customer>
In this example, name and city are fields that hold values. The XML Mapping Pane in Microsoft Word displays XML data stored in a document and lets you connect that data to content controls, which are editable boxes in a document, such as text fields.
To open the pane in Microsoft Word: go to the Developer tab and click XML Mapping Pane. Choose the data from the Custom XML Part list. Its fields, such as name and city, appear in a tree that you can expand.
Map XML data
Mapping connects a content control to one XML field. The control displays that field's value. When the control is mapped correctly, changing its value updates the XML data, and changing the mapped data updates the control.
Here is how to map a field in Microsoft Word:
- Add the XML data to the document. In the XML Mapping Pane, choose Add new part and select the
.xmlfile. - Click where you want the value to appear.
- In the XML Mapping Pane, right-click a field, such as
name, and choose Insert Content Control > Plain Text. - The control appears with the value from the XML field. It remains linked to that field.
XML mapping is an advanced feature used mostly by developers and teams that create many documents from stored data, such as letters filled in with customer details. The XML Mapping Pane is not available in the sandbox, so practise this part in Microsoft Word. You can practise the protection features below in the sandbox.
Now that you've seen how XML data connects to documents, let's look at how to control what people can change.
Restrict editing
Restrict Editing limits which changes people can make to a document. First, choose what people are allowed to do. Then turn on, or enforce, that restriction.
- Go to Review > Restrict Editing. A pane opens at the side of the document.
- Under Editing restrictions, tick the box and choose what people are allowed to do:
| Choice | People can only… |
|---|---|
| No changes (Read only) | Read the document |
| Comments | Add comments |
| Tracked changes | Edit while Word marks each edit for review |
| Filling in forms | Fill in the form fields |
- Click Yes, Start Enforcing Protection.
- Type a password twice, or leave the password box empty, and click OK.
To turn protection off, open Restrict Editing again and click Stop Protection. If you set a password, you must enter it.
If you set a password, write it down and keep it somewhere safe. Without it, you may not be able to stop protection yourself. Editing restrictions help prevent accidental changes, but they are not strong security. For confidential documents, use proper encryption and access controls.
Read-only documents
You can discourage or prevent editing in a few different ways. Choose the method that matches how much control you need:
- Restrict Editing > No changes (Read only), as above. People can read, select, and copy the text, but they cannot change it while this restriction is on.
- Mark as Final (Microsoft Word: File > Info > Protect Document). Word displays a banner saying the document is final. Readers can still click Edit Anyway, so this is a reminder, not a lock.
- Share a PDF (Lesson 22). A PDF usually keeps the page layout the same and is less likely to be changed by accident. It does not prevent someone from editing the file.
Protected form filling
A form should let people fill in its fields without changing the questions or labels. Choose Filling in forms under Restrict Editing to allow people to complete the fields while protecting the rest of the document.
- Build the form with form fields (Lesson 23).
- Go to Review > Restrict Editing.
- Choose Filling in forms and click Yes, Start Enforcing Protection.
With protection on:
- Clicking takes you to a form field, and Tab moves from one field to the next.
- You can tick check boxes and choose an option from a drop-down.
- You cannot change the labels or other text outside the fields.
Test a protected form before sending it. Fill in every field, press Tab to move through them, and try each drop-down. Then stop protection, clear your test answers, and turn protection on again.
Common mistakes
| Mistake | What happens | How to fix it |
|---|---|---|
| Forgetting to click Start Enforcing Protection | Nothing is restricted | Open Restrict Editing and start enforcing |
| Protecting the wrong way, such as Read only for a form | Nobody can fill in the fields | Stop protection and choose Filling in forms |
| Forgetting the password | You can't edit your own document | Keep passwords somewhere safe |
| Editing the form while it's protected | Your changes are blocked | Stop Protection, edit, then protect again |
| Expecting XML mapping in the sandbox | The pane isn't there | Use Microsoft Word for XML mapping |
Exercise
Click New in the sandbox title bar, and type This policy was approved by the board. Then do each task and press Check.
Chapter project
Put Chapter 9 together, with tables from Chapter 4. You'll build a registration form, test it, and protect it for filling in.
Event registration form
What to remember
- The XML Mapping Pane (Microsoft Word, Developer tab) shows XML data stored in a document.
- Mapping links a content control to an XML field so they stay in sync.
- Review > Restrict Editing limits changes: read only, comments, tracked changes, or filling in forms.
- Restrictions only apply after Start Enforcing Protection; Stop Protection turns them off.
- Use Filling in forms for forms, and test them before sending.
- Editing restrictions prevent accidents; they aren't strong security.
That's the end of Chapter 9. In Chapter 10, you'll put everything together in real-world projects.