Chapter 4. Structure Basics

<feature><title>Chapter Objectives</title>

In this chapter you will learn how to:

<objective>

Create/import XML tags

</objective>
<objective>

Create a structured layout

</objective>
<objective>

Import XML

</objective>
<objective>

Flow XML into a structured layout

</objective>
<objective>

Work with InDesign’s Structure pane

</objective>
</feature>

This chapter introduces you to InDesign’s XML tools and capabilities. We have chosen a simple, real-world project on which to cut your XML teeth, because the best way to learn how to do something is to actually do it. As the ABCs are often the first thing we learn as children, designing business cards is basic to the vocabulary of the average designer.

By its description a business card is the very definition of a structured document. First, business cards use a standard design: fonts, color, and placement are identical on each card. Second, each card contains the name, title, and contact information for one employee, as well as the company name, logo, and address. In effect, each business card is a single record in the corporate database.

Let’s start by opening a partially finished version of the project that’ll jump start your XML education and show you what a completed project looks like.

Note

Download all files for Chapter 4 from www.peachpit.com/indesignxmlguide and copy them to a folder on your hard drive (approximately 2 MB).

Sample Project: One-Up Business Card

The following lessons begin your education in how XML works with InDesign by creating a simple data-driven project.

Lesson 4-1: XML Foundation

Scenario: You have just received a job from a new customer. The company hired six new employees and wants you to create a business card for each. An XML-savvy coworker set up an InDesign template and forwarded the layout and XML to you for completion.

  1. Open 1card.indt from the Project 1 folder (Figure 4.1).

    The sample business card is already structured and tagged. It is ready for you to import the XML data.

    Figure 4.1. The sample business card is already structured and tagged. It is ready for you to import the XML data.

    Note

    All project files have been saved as templates (.INDT files) to prevent you from saving over the master files accidentally.

  2. Display the Structure pane and the Tags panel.

    Select View > Structure > Show Structure.

  3. Show Tag Markers and Tagged Frames.

    Select View > Structure > Show Tagged Frames.

  4. Select Show Text Snippets from the Structure pane menu.

    Before we go any further, take a moment to study the layout of the structured business card on the screen. Pay special attention to the colorful brackets and frames around the XML placeholder text. Later in the chapter we take you through the process step by step and explain in detail the ins and outs of constructing a structured layout. For the time being, sit back and enjoy the magic that’s about to explode on your screen.

  5. Select the dataroot element in the Structure pane (Figure 4.2).

    Always select the root element before importing the XML.

    Figure 4.2. Always select the root element before importing the XML.

  6. Select File > Import XML.

    There are three places in InDesign where you can invoke the import XML command:

    • From the File menu.

    • From the Structure pane menu.

    • By right-clicking on a Root or other element within the Structure pane itself.

    Don’t worry. These commands all perform the same task; pick the one you prefer or use the one most convenient at the time.

  7. Select employees.xml from the Project 1 folder.

    Click the Show XML Import Options (Figure 4.3) checkbox to select it. After your XML structure is built, this checkbox should be your default selection.

    In most structured layouts you’ll want to access the XML Import Options.

    Figure 4.3. In most structured layouts you’ll want to access the XML Import Options.

    • Import Into Selected Element is also a default selection. If this is checked, InDesign flows the XML content into the selected tree or element—unchecked, the text flows only into the root element of the Structure pane.

    • Merge Content replaces any existing XML content that matches the imported XML structure.

    • Use Append Content when you want to import additional data into your layout.

  8. Click Open.

  9. When the XML Import Options dialog (Figure 4.5) appears, turn on the following onscreen selections:

    It’s essential that you understand how the XML Import Option dialog affects the import of the XML content. For a full description of these options, see Chapter 1.

    Figure 4.5. It’s essential that you understand how the XML Import Option dialog affects the import of the XML content. For a full description of these options, see Chapter 1.

    Turn off all the rest.

  10. Click OK.

If everything went well, the XML placeholders have been replaced by the name, title, phone number, and email address of the first employee listed in the XML file (Figure 4.6). In the Structure pane you will see six employees elements. Here are some of things we want you to notice:

  • Each element of the XML data landed in the placeholder tagged for that element. For example: the employee’s first name replaced the placeholder tagged as [Efirstname], his last name replaced the placeholder tagged [Elastname], and so on.

  • Only the data from the first employee listed in the XML landed in the text frame.

  • The Structure pane displays six employees elements in total. Note that the first employees icon is different from the others, indicating that this element has been placed into the document (Figure 4.7).

  • All elements in the layout are still tagged with the XML structure.

Once the XML is imported correctly, this is what you should see. The Structure pane displays six employees elements, and your placeholders have been replaced by the elements of the first record.

Figure 4.6. Once the XML is imported correctly, this is what you should see. The Structure pane displays six employees elements, and your placeholders have been replaced by the elements of the first record.

The Structure pane is a handy reference during XML workflows. It displays a wealth of information about the imported XML file, such as how many elements have been imported; the names of the elements; and, if snippets are turned on, a glimpse of the XML content as well. It can also tell you which elements may already be in your layout; here we can see by the change in the first element icon that “Jim James” is on page 1.

Figure 4.7. The Structure pane is a handy reference during XML workflows. It displays a wealth of information about the imported XML file, such as how many elements have been imported; the names of the elements; and, if snippets are turned on, a glimpse of the XML content as well. It can also tell you which elements may already be in your layout; here we can see by the change in the first element icon that “Jim James” is on page 1.

Although the previous example could be mildly entertaining to a jaded designer, the next exercise can knock your socks off.

Lesson 4-2: Fun with the Structure pane

By importing the XML into a structured layout in Lesson 4-1, you created a living relationship between imported XML and the structured document. Let’s explore some of the powers of this relationship:

  1. Open the element for the second employee in the Structure pane.

  2. Click and drag the icon for this employee’s element and drop it on the tagged text frame on your layout (Figure 4.8). Watch out for two potential errors here:

    • You could accidentally select and drag a child element to the layout instead of the parent.

    • You could drop the element outside of the text frame.

    Each employees parent element contains five child elements: Efirstname, Elastname, Etitle, and so on. Dragging the parent icon over the structured layout causes InDesign to swap the existing child elements with the one selected.

    Figure 4.8. Each employees parent element contains five child elements: Efirstname, Elastname, Etitle, and so on. Dragging the parent icon over the structured layout causes InDesign to swap the existing child elements with the one selected.

    The information from the second employee has now replaced all the information from the first (Figure 4.9). Notice the following:

    • The new information completely replaced the old information.

    • The new information assumed the exact placement and formatting as the old.

    • The icon for the second employee now indicates that it has been placed in the layout, while the icon for the first employee has returned to the default setting.

    The second record completely replaces the first and adopts the formatting, too. It’s like magic.

    Figure 4.9. The second record completely replaces the first and adopts the formatting, too. It’s like magic.

  3. Drag the first employees element back to the layout.

    So far, we have demonstrated that the relationship between the structured layout and the XML is dynamic. Because the employee information is stored in identically named fields, you can replace any data in the layout with a similar record from the Structure pane.

    We’re sure you are thinking right about now, “This is great for the first layout, but we need to make six identical business cards!”

    Here’s where you had better hold onto your hosiery.

  4. Create a new page from A-Master (Figure 4.10).

    Dragging the A-Master icon to the Document pages area of the Pages panel creates a new page with features identical to page 1. The master page contains the company logo, address, and a text frame needed to make the next business card.

    Figure 4.10. Dragging the A-Master icon to the Document pages area of the Pages panel creates a new page with features identical to page 1. The master page contains the company logo, address, and a text frame needed to make the next business card.

    Page 2 features the logo, company address, and a text frame all generated by the master page. If you cannot see the edges of this text frame, select View > Show Frame Edges.

  5. Drag the second employees element from the Structure pane into the empty text frame on page 2.

The information from the second employee should appear in the empty frame on page 2. The layout and formatting should be identical to page 1.

Wow! The structure layout from page 1 has magically transferred itself to page 2. Still have your socks? Well, we are determined to see you barefoot before the end of this lesson.

Lesson 4-3: Data Integrity

It would be a simple matter now to add four more pages to the document, drag in the remaining employee records, and finish the project. But you still have more things to learn about how XML can save you time, money, your job, and create world peace. (Okay, the last one may be reaching a bit.)

In the past, clients passed sheets of paper to designers with the names and contact info for their new employees. This info then had to be reentered into layouts manually by the designer. It is a process that often led to typos, transpositions, and other errors, delays, and costly corrections. On occasion it may have also cost the designer a client or two. The process has been improved since the introduction of email and digital files, which can be supplied by the client. But copying and pasting can lead to errors, too. XML eliminates these types of mistakes altogether.

Today, employee data is stored in databases. Current databases can export the data (names, titles, phones, and so on) directly to XML. In an XML workflow, the data can travel directly from the HR department to your layout without the need for further transcribing. This way, typos now are the responsibility of the HR manager, which certainly makes us designers sleep better at night. The result: time, money, job—all saved!

There are other benefits to using XML. A few years ago, we were laying out sheets of business cards 18-up, three columns of six cards each. The printer ran 500 sheets through the press (18 employees’ worth at a time), and each of the 18 employees got 500 cards. In the process of creating cards for over 100 employees, two employees’ cards were accidentally printed twice. Not a big deal in the overall scheme of things, but a waste of resources nonetheless. If we had been using an XML workflow at the time, the duplication would never have happened.

Let’s see how XML prevents unintentional data duplication:

  1. Observe the employee’s name on page 2 of your layout, as seen back in Figure 4.6.

  2. Drag the element of the first employee from the Structure pane to the text frame on page 2.

    We’re sure when you see the first employee’s name and info replace the data on page 2, you’ll think, “Hey, I just made two cards for the first employee!”

    But you’d be wrong, bucko.

  3. Navigate to page 1.

    Page 1 is blank.

  4. Drag the first employee element to the blank text frame on page 1.

    The first employee’s info reappears on page 1.

  5. Navigate to page 2.

    Page 2 is blank.

  6. Delete page 2.

Lesson 4-4: Layout Automation

Up to this point you may already be seeing the value in developing an XML workflow: XML can get the data from the client to your page error-free and prevent unwanted data duplication. This is a win-win proposition in anyone’s book. Yet we have barely scratched the surface of what XML can do for you, your company, and your clients. How would you like to add automation to the mix as well?

The first card was created automatically when you imported the XML. But the second card required you to add a page and drag out the next data element manually. For each of the remaining employees, these two steps would have to be repeated. Not a big deal for six business cards, but what if you had to do hundreds or thousands? This is where XML really shines.

Let’s see how XML can automate the process:

  1. Navigate to page 1.

  2. Select the text frame on page 1 with the Selection tool.

  3. Observe the text frame’s out port.

The out port is empty, indicating that there is no more text to place.

It may be confusing at first to see the empty out port because you know there are six employees and that this card represents only one record. You can obviously see that there are five more elements in the Structure (Figure 4.11). So then, where is the rest of the text?

By looking at the Structure pane it is easy to assume that all the information displayed should flow into a single text frame.

Figure 4.11. By looking at the Structure pane it is easy to assume that all the information displayed should flow into a single text frame.

In Chapter 1, you learned that XML is simply plain text. But when InDesign imports it into the Structure pane, it treats it as a wholly different animal. InDesign interprets the XML structure and understands that each employees element is a standalone entity, a single record in a database. This capability to differentiate one record from another is the reason InDesign knows how to import the XML content into the structured layout and how to replace one record with another.

As we drag the next employees element into the text frame, InDesign substitutes each element on the card with a similarly tagged element of the new record. No matter how many employees icons you drag onto the frame, you can never get more than one record at a time. So, is it even possible to flow all the records automatically? Yes.

It may help to imagine the employees elements as several cul-de-sacs branching off a main road. Each branch of the XML tree represents an intersection at the entrance to a cul-de-sac (one employee’s record). Dataroot, on the other hand, represents the main road that links them all together.

Did this help you figure out the answer? Try this:

  1. Drag dataroot to the text frame on page 1.

    Did you notice that the color of the main text frame changed?

  2. Select the text frame on page 1 with the Selection tool.

    • The Tag panel indicates that the frame is now tagged as dataroot.

    • The out port indicates overset text.

  3. Create a new page based on A-Master as we did in Figure 4.10.

  4. Click the out port from the text frame on page 1.

  5. Display page 2.

  6. Shift-click the loaded text icon on the empty text frame on page 2 to autoflow (Figure 4.12).

    Watch for the solid serpentine arrow when you hold the Shift key, indicating that the XML will autoflow into your structured layout.

    Figure 4.12. Watch for the solid serpentine arrow when you hold the Shift key, indicating that the XML will autoflow into your structured layout.

Note

To autoflow properly, place the Note over the existing text frame. If you miss the existing frame, InDesign will generate one of its own, which will not be linked to the master text frame. If you experience this error, stop, Undo, go back to page 2, and try again.

Warning

Autoflow also may not function correctly when text frames are manually overridden from the master. The best solution is to delete and re-create the page from the master on the Pages panel.

As the XML flows from the Structure pane into the layout, each record automatically creates a page for itself (Figure 4.13). You should have at least six new cards when it’s finished flowing. A blank seventh card may appear because of the hard return inserted at the end of the last record. Extra pages can be deleted without harm.

The Pages panel will be your first indication that the autoflow worked properly. Six additional cards should be created by the XML data. The last card is blank thanks to a hard return inserted after the email placeholder. The blank card can be deleted.

Figure 4.13. The Pages panel will be your first indication that the autoflow worked properly. Six additional cards should be created by the XML data. The last card is blank thanks to a hard return inserted after the email placeholder. The blank card can be deleted.

No matter how many times we demonstrate this task, we end up with these silly grins on our faces thinking about how cool this is. At seminars and workshops, it’s usually easy to tell who in the audience are production designers because they are smiling, too.

Review

Here’s what you have learned so far:

  • InDesign treats the XML as a standalone database and is able to differentiate one record from another.

  • Each branch (child) element in the Structure pane is an entity separate and distinct from all the others.

  • When XML is imported into a structured layout, the imported data assumes the same placement and formatting as in the original placeholder.

  • To flow multiple records the layout must target a root element.

Sample Project: 6-Up Business Cards

Lessons 4-14-4 established the basic concepts you need to go forward in an XML workflow. But we’re sure some of you are saying, “Hey, I can’t print business cards one at a time! I need a press-ready layout.” And you’re right.

Lesson 4-5: XML Foundation Part 2

In this project we apply the things you have already learned to create a 6-up, production-ready version of the same job.

  1. Open 6cards.indt from the Project 1 folder.

  2. Select View > Show Text Threads.

  3. Make sure all the Structure markers are turned on.

  4. Select any of the tagged text frames on the layout (Figure 4.14).

    This is one of the possible ways to lay out a press-ready structure. The text frames are linked together from left to right and then down. You could also go top to bottom and then across, it’s up to you. The XML will work either way.

    Figure 4.14. This is one of the possible ways to lay out a press-ready structure. The text frames are linked together from left to right and then down. You could also go top to bottom and then across, it’s up to you. The XML will work either way.

    • All the text frames are linked together on the layout.

    • All the frames are tagged with the employees element.

    • In the first card, text placeholders have already been created, formatted, and tagged for the XML structure.

  5. Select the dataroot element.

  6. Import employees.xml.

  7. Observe the XML Import Options dialog. The checkboxes used for Lesson 4-1 should still be selected. If so, click OK.

    After the XML import is complete, the first employee’s name and information appears in the first card. The data from the remaining five employees appears in the Structure pane but not in your layout. Why?

    The color of the tagged frame should give you a hint. Notice how the color of the text frame is the same color as the tag for the employees element? Although there are frames ready for each of the six employees, the structure in the layout is tagged to allow only one element into it at a time. Knowing what you know now, have you figured out how to fix the problem? Right, it’s the same way you fixed the single-card layout in Lesson 4-4.

  8. Drag the dataroot element from the Structure pane onto the tagged text frame.

    • The color of the tagged frames changes to the color of the dataroot element.

    • Six cards are now filled with the data of the six new employees.

    • All the information is properly laid out and formatted (Figure 4.15).

      More magic. Six cards completely finished and ready for the press.

      Figure 4.15. More magic. Six cards completely finished and ready for the press.

Quick, look down! Got socks?

No matter how jaded you are as a designer, that will put a smile on your face. In barely the time it took you to blink, six business cards are finished and ready to be printed. Had the XML contained 600 names, all 600 cards could be finished in less than the time it takes you to read this paragraph. Wow!

Now that we’ve got your attention, it’s time to show you how to do this magic trick for yourself. And, unlike David Copperfield, there’s no magician’s union to prevent us from showing you how all it works.

Creating Structured Layouts

In the following lessons we take you step by step through setting up a structured layout.

Lesson 4-6: Basic Document Setup

Let’s start with the basic document setup:

  1. Select File > New > Document.

  2. Set up the document with the specifications appearing in Figure 4.16. Click OK.

    Create a new document with these specifications.

    Figure 4.16. Create a new document with these specifications.

We’re not going to worry about the company logo and return address; these are elements you can add later if you desire. Instead, let’s concentrate on the XML portion of the design.

The first issue we have to address is creating or obtaining the XML structure. There are three methods you can use for populating the Tags panel:

  • Manually, using the Tags panel to create each tag

  • By loading the tags from an existing InDesign document or XML file

  • By loading a DTD

We experiment with the first two options in this exercise, but reserve the DTD for Chapter 11.

Lesson 4-7: Creating Your Own Tags

The tags displayed in the Tags panel reflect the underlying structure of an XML file. Some of the names refer to “content” elements (Efirstname, Elastname, and so on) and some refer to “organizational” elements (dataroot, employees). If you create these tags manually, don’t forget to follow the basic XML rules from Chapter 11. Remember, the tag names in the panel must be identical in every way to those from the XML file itself. Any deviation, no matter how trivial, will invalidate the tag.

Here’s a complete list of the tags from employees.xml:

  • dataroot

  • employees

  • Employeeid

  • Efirstname

  • Elastname

  • Etitle

  • Ephone

  • Eemail

  • Ephoto

Lesson 4-7A: Creating Tags Manually

To create a tag manually, do the following:

  1. If the Tags panel is not visible, select Window > Tags to display the panel.

  2. Select New Tag from the Tags panel menu (Figure 4.17).

    InDesign allows you to create, edit, and delete tag names through the Tags panel.

    Figure 4.17. InDesign allows you to create, edit, and delete tag names through the Tags panel.

    You can also create tags by clicking the New Tag button at the bottom of the Tags panel. Use the button when you want to create tags quickly and you don’t care what color is assigned to it. Pressing the button doesn’t open the New Tag dialog, so double-click on the tag name to access the Tag Option dialog for editing the tag name and color.

  3. Type Efirstname into the New Tag dialog. You can use the sequential color selected by InDesign or choose from the Color pull-down menu (Figure 4.18). Click OK.

    InDesign assigns colors sequentially from the Color drop-down list. Feel free to change these color assignments. The colors have no effect on the XML or the structure.

    Figure 4.18. InDesign assigns colors sequentially from the Color drop-down list. Feel free to change these color assignments. The colors have no effect on the XML or the structure.

    The Efirstname tag appears in the Tags panel.

  4. Create a tag for Elastname.

Lesson 4-7B: Editing Existing Tag Names

To edit existing tag names, do the following:

  1. Double-click the root tag in the Tags palette.

    The Tag Options dialog appears.

  2. Change the tag name to dataroot.

    Note the case and spelling as you type.

  3. Click OK.

Lesson 4-7C: Importing Tag Names

To import tag names from an existing InDesign or XML file, do the following:

  1. Select Load Tags from the Tags panel menu (Figure 4.19).

    By loading tag names from existing InDesign documents or the actual XML itself, you will avoid all the pitfalls of misspellings and case sensitivities. If the XML file is available, it’s always the first choice.

    Figure 4.19. By loading tag names from existing InDesign documents or the actual XML itself, you will avoid all the pitfalls of misspellings and case sensitivities. If the XML file is available, it’s always the first choice.

  2. Select employees.xml.

    You could also select 1card.indt or 6cards.indt. Because these InDesign templates already have the identical XML structure you’re looking for, you can obtain the needed tags from them as well.

  3. Click Open.

    The Tags panel is populated by all the tag names used in the XML file (Figure 4.20).

    Tag names are listed in alphabetical order, not in the order in which they appear in the XML structure.

    Figure 4.20. Tag names are listed in alphabetical order, not in the order in which they appear in the XML structure.

    InDesign assigns colors for the tag names sequentially from the default color list.

Lesson 4-8: Creating a Structured Layout

In most cases, structured layouts start on your master pages:

  1. Display the A-Master.

  2. Create a text frame within the visible margins (Figure 4.21).

    By drawing a text frame on the master page, you are creating a target you’ll need for autoflowing the XML content later.

    Figure 4.21. By drawing a text frame on the master page, you are creating a target you’ll need for autoflowing the XML content later.

    Warning

    In most cases tags should not be applied to items on the master page. Doing so will cause the XML, when it’s imported, to populate the placeholders on the master page. The resulting content will then appear on every page of your document.

  3. Display page 1.

  4. Command-Shift-click to override the master text frame on page 1.

    The text frame should display a bounding box and in and out ports, indicating that it has been overridden.

  5. Insert the Text cursor in the frame and create text placeholders for your XML content (Figure 4.22).

    What you type for the XML placeholders doesn’t matter as much as how you tag them. You could just as easily use A, B, C, D... or 1, 2, 3, 4.

    Figure 4.22. What you type for the XML placeholders doesn’t matter as much as how you tag them. You could just as easily use A, B, C, D... or 1, 2, 3, 4.

    What you type is unimportant. You can use any text you want for the placeholders; here is what we used: First Last, Title, Phone, Email. Use single hard returns or spaces to break lines or separate placeholders.

  6. In the last line of the text frame after the Email placeholder, press Return/Enter to insert a hard return.

    Although you may not be in the habit of normally doing so, you must add a single hard return after the last item: Email. The extra hard return at the end of the business card ensures that each record occupies its own distinct card.

    The placement and spacing you saw in the sample business cards were specified by styles using exact font and paragraph formatting. To duplicate that look, you will need similar styles of your own. Luckily, you can save some time by importing them from one of the templates we’ve already explored.

  7. Display the Paragraph Styles panel.

  8. Select Load All Text Styles... from the Paragraph Styles panel menu (Figure 4.23).

    There’s no point in wasting time setting up Paragraph styles when you can load them from an existing template.

    Figure 4.23. There’s no point in wasting time setting up Paragraph styles when you can load them from an existing template.

  9. Select 1card.indt in the Open a File dialog. Click Open.

    The Load Styles dialog appears.

  10. Make sure all the style names are checked. Click OK.

    The styles from 1card.indt appear in the Paragraph Styles panel.

  11. Apply paragraph styles to your placeholders that match their names. Because there are no “First” or “Last” styles, apply the Employee style to the first line.

    The placeholder formatting should now match 1card.indt (Figure 4.24).

    The basic layout is complete but lacks its XML structure.

    Figure 4.24. The basic layout is complete but lacks its XML structure.

Lesson 4-9: Tagging Placeholders

Okay, now all the elements are in place to finish our structure. The final step in the process is to apply XML tags to the various placeholders. Tags identify which elements get imported from the XML file and where they land into your layout. This is the way you should tag the placeholders:

  1. Select the Text tool.

  2. Select the word First. Be careful not to select the space between the words First and Last.

    Warning

    InDesign provides several shortcut methods for selecting text—for example, double-, triple-, and quadruple-clicking. Abstain from triple- and quadruple-clicking during the tagging process. The reason is simple: Quadruple-clicking to select a line or paragraph automatically selects the hard return, too. Because the imported XML replaces anything that resides within the tag brackets, you may suddenly see the spaces between your elements disappear, along with tabs and hard returns.

  3. Click Efirstname in the Tags panel (Figure 4.26).

    Careful, careful! Mind how you tag that element. Tagging seems simple enough, but plenty of errors can be caused during this process.

    Figure 4.26. Careful, careful! Mind how you tag that element. Tagging seems simple enough, but plenty of errors can be caused during this process.

    • Brackets appear at the beginning and end of the word [First].

    • The bracket color matches the color of the Efirstname element in the Tags panel.

    • The color of the text frame has also changed.

  4. Switch to the Selection tool and click the text frame.

    The text frame is tagged with the Story tag (Figure 4.27).

    See, we told you! InDesign demonstrates it has a mind of its own sometimes—it tagged text frame with the Story element. If you had missed this error, you wouldn’t realize something was wrong until later. When you try to import the XML, InDesign would ignore your placeholders altogether because Story is not part of the structure.

    Figure 4.27. See, we told you! InDesign demonstrates it has a mind of its own sometimes—it tagged text frame with the Story element. If you had missed this error, you wouldn’t realize something was wrong until later. When you try to import the XML, InDesign would ignore your placeholders altogether because Story is not part of the structure.

    Whoa! Story is not one of the elements from the XML file, so where did it come from? The answer: InDesign created it. If you remember from Lesson 4-4, the text frame was tagged with the employees element. Because you did not tag the text frame yourself, InDesign did it for you. And instead of using one of the existing tags, it created one of its own.

    Unfortunately, this presumptuous bit of creativity is totally unacceptable, and for good reason. By using Story, which is not an element in your XML file, InDesign has broken the structure. If you tried to import XML at this moment it would fail.

    But don’t worry, there’s an easy fix.

  5. Select the Story element in the Structure pane (Figure 4.28).

    To fix the text frame, first click on the Story element in the Structure pane.

    Figure 4.28. To fix the text frame, first click on the Story element in the Structure pane.

  6. Click employees in the Tags panel (Figure 4.29).

    Click the employees element in the Tags panel to rename the Story tag in the Structure pane.

    Figure 4.29. Click the employees element in the Tags panel to rename the Story tag in the Structure pane.

    • Story is replaced by employees in the Structure pane.

    • The color of the text frame matches the employees element in the Tags panel.

  7. Apply the appropriate tags to the remaining placeholders.

    All placeholders are tagged properly (Figure 4.30).

    On the left you can see what correctly tagged placeholders look like. To the right you can see tags enclosing spaces and hard returns alike. The simplest fix is to select the whole mess, untag it, and start over from scratch.

    Figure 4.30. On the left you can see what correctly tagged placeholders look like. To the right you can see tags enclosing spaces and hard returns alike. The simplest fix is to select the whole mess, untag it, and start over from scratch.

Lesson 4-10: Preserving Paragraph Formatting

The project is nearly ready, but not quite. Should you try to import the XML file at this point and flow the content to additional pages, you would receive a disturbing surprise: The first card created by the XML would be okay, but all additional cards generated would ignore your carefully applied text formatting (Figure 4.31). Egads!

Don’t import the XML yet! This is what will happen if you try. For some reason, InDesign refuses to clone the formatting on every element. Map tags to Paragraph and Character styles to preserve the formatting.

Figure 4.31. Don’t import the XML yet! This is what will happen if you try. For some reason, InDesign refuses to clone the formatting on every element. Map tags to Paragraph and Character styles to preserve the formatting.

To preserve all your hard work, you need to lock down the original design, which is based largely on Paragraph styles. You do this by creating a formal relationship (mapping) between the XML tags and your Paragraph styles. InDesign gives you two ways to access this feature:

  1. Select Map Tags to Styles from the Tags panel menu, or the Structure pane menu (Figure 4.32).

    You can access the mapping feature from the Structure pane or the Tags panel.

    Figure 4.32. You can access the mapping feature from the Structure pane or the Tags panel.

    The Map Tags to Styles dialog appears.

  2. Click Map by Name.

    This option automatically pairs tags to styles when their names match (Figure 4.33).

    With a little foresight you can automate the mapping procedure by naming your styles after the XML tags or vice versa. As always, spelling and case matter.

    Figure 4.33. With a little foresight you can automate the mapping procedure by naming your styles after the XML tags or vice versa. As always, spelling and case matter.

    All the placeholder tags are matched except for Efirstname and Elastname. There are no styles named for these tags. Instead, map the Employee Paragraph style to each. (You could get away with mapping the Employee style to one or the other, but we’d rather be safe.)

  3. Match the Employee style to the Efirstname tag in the Map Tags to Styles dialog (Figure 4.34).

    Tags that don’t have a style match can be assigned to any Paragraph or Character style in the list. There are no limitations or rules here. Go ahead and create a style for each tag or assign many tags to one style. It’s up to you.

    Figure 4.34. Tags that don’t have a style match can be assigned to any Paragraph or Character style in the list. There are no limitations or rules here. Go ahead and create a style for each tag or assign many tags to one style. It’s up to you.

  4. Click OK.

Congratulations! Your document is completely structured and ready for XML.

Lesson 4-11: Testing Your Structure

Let’s test the structure and see if everything works.

  1. Select dataroot in the Structure pane.

  2. Import employees.xml.

  3. In the XML Import Options dialog, select only the following checkboxes:

    • Clone repeating text elements

    • Only import elements that match existing structure

    • Do not import contents of whitespace-only elements

  4. Click OK.

    The XML content should replace your placeholders as in Lesson 4-1.

  5. Drag dataroot to the text frame.

    • The text frame changes color, indicating it is now tagged for the element dataroot.

    • The overset icon should be visible in the out port.

  6. Load the overset text.

  7. Create a new page from the A-Master.

  8. Autoflow the text into the master text frame on page 2.

    • Six pages should appear in the Pages panel.

    • Each page contains one of the six employees.

    • Each page is formatted identically.

Lesson 4-12: Press-Ready Docs

By this point you should be ready to tackle the 6-up layout. The steps and techniques for a sheet of cards are nearly identical to the single-card lesson; only the logistics vary a bit. Follow these steps:

  1. Create a New Document with the specifications shown in Figure 4.35.

    These specs create the 6-up layout.

    Figure 4.35. These specs create the 6-up layout.

  2. Display A-Master.

  3. Select Layout > Create Guides.

    The Create Guides dialog appears.

  4. Create row guides from the specifications shown in Figure 4.36.

    Create Guides is a great timesaver for setting up multiple ruler guides. Notice the options for fitting the guides to Margins, or to Page, and to Remove Existing Ruler Guides.

    Figure 4.36. Create Guides is a great timesaver for setting up multiple ruler guides. Notice the options for fitting the guides to Margins, or to Page, and to Remove Existing Ruler Guides.

  5. Select the Text tool.

  6. Draw a text frame in the area defined by the guides for the first card structure.

  7. Switch to the Selection tool.

  8. Click the out port of the text frame.

  9. Option-drag (Alt-drag) (semi-autoflow) a new text frame in the second column, first row (Figure 4.37).

    Hold the Option (Alt) key to access the dotted serpentine arrow of semi-autoflow. This technique saves some time by reloading the text frame icon automatically after drawing a new frame.

    Figure 4.37. Hold the Option (Alt) key to access the dotted serpentine arrow of semi-autoflow. This technique saves some time by reloading the text frame icon automatically after drawing a new frame.

  10. Option-drag (Alt-drag) text frames in the remaining rows and columns.

    You now have six linked master text frames.

  11. Display page 1.

  12. Override the first master text frame.

  13. Repeat Lessons 4-8, 4-9, and 4-10 to create a structured layout in this text frame.

    The layout is ready for XML (Figure 4.38).

    The structured press-ready layout awaits the XML.

    Figure 4.38. The structured press-ready layout awaits the XML.

  14. Select dataroot in the Structure pane.

  15. Import employees.xml.

  16. In the XML Import Options dialog, select only the following checkboxes:

    • Clone repeating text elements

    • Only import elements that match existing structure

    • Do not import contents of whitespace-only elements

  17. Click OK.

    • The XML content should replace your placeholders as in the original example.

    • Only the first record is displayed in your layout.

    • The threaded frames are tagged for the employees element.

  18. Drag dataroot to the text frame.

    • All six employees appear in the layout

    • All frames should be identically formatted.

That’s it, you’ve passed the first test. You have learned the foundational concepts that will allow you to create successful XML workflows. In the coming chapters you will expand this knowledge and understanding and fill your toolbox with all sorts of useful XML tips and tricks.

Review

Remember what you learned in this hands-on tutorial; these important lessons will be invaluable in the next chapter:

  • How to create, import and edit tags

  • Proper placeholder tagging techniques

  • XML element sequence and nesting

  • Mapping tags to styles

The Wrong Way

You might think “The Wrong Way” is an odd title for a section. Why would you want to teach someone the “wrong” way to do something? The reason is simple: We are firm believers that you learn as much from your mistakes as from your successes. We are also confident that as you learn more about XML and structured layouts, you may think of various alternative techniques for creating dynamic workflows. In addition to learning the “right” way to build a dynamic document with XML, you should have some experience in knowing when a particular method won’t work. We know this because extensive experimentation and trial-and-error (lots of error!) is how we learned so much about how XML works with InDesign.

Like all early explorers and pioneers setting off in any field to discover new worlds and establish new ways of life, we wandered into the XML/InDesign wilderness alone and mostly unaided. Some tried to help and gave us tantalizing glimpses of what was possible in this brave new world, but there were few concrete examples. Most of the things we thought XML could do were simply conjecture. Over several months of investigation, often filled with frustration and frequent failure, we developed the methods we’re now teaching you.

In this chapter, you learned how to create a structured layout using tagged text that automatically generates single or multiple business cards. There’s no doubt that our approach works, but is our preferred method the only one? The simple answer is no.

In the following lessons we briefly explore the “floating frame” technique: an alternate XML method we toyed with for weeks without success. By learning why it fails, it may lay for you (as it did for us) a better foundation for understanding how XML does (and does not) function with InDesign.

Lesson 4-13: Floating Frames Method

For designers experienced with corporate identity projects, our preferred method, using a single frame containing tagged and styled text, may not have been your first choice. Instead, your design may have favored several, independent frames like the one in Figure 4.41.

Here you see two possible methods for laying a typical business card. Normally, the choice would be a personal preference and nothing more. You will see how alternative B is the “wrong way” in most XML workflows.

Figure 4.41. Here you see two possible methods for laying a typical business card. Normally, the choice would be a personal preference and nothing more. You will see how alternative B is the “wrong way” in most XML workflows.

Let’s take a few minutes to explore an alternative method for creating a structured, dynamic layout:

  1. Create a new document as in Lesson 4-6.

  2. Select the Text tool.

  3. Draw individual text frames for each element on your business card. You will need one for the employee’s name, title, phone, and email address. Remember to make the frames large enough to hold the longest name, title, and so on.

  4. Type placeholder text into each of your text frames.

  5. Load all text styles from 1card.indt as in Lesson 4-8.

  6. Apply the styles to each placeholder as appropriate.

  7. Load the XML tags names from the employees.xml file, as in Lesson 4-7C.

  8. Switch to the Selection tool.

  9. Select the frame containing the title placeholder.

  10. Click Etitle in the Tags panel.

    The frame containing the title changes color, indicating it is tagged for the Etitle element.

  11. Tag the frames containing the phone and email placeholders as appropriate.

Lesson 4-14: Creating Nested Elements

Now we confront one of several problems we’re going to face during this lesson. The only frame left untagged contains the placeholders for both the first and last names. So the question is which tag do you use? Efirstname? Elastname?

The answer is simply that neither will actually solve the problem. If the frame is tagged for the first name only, the first name lands in the frame; if the frame is tagged for the last name, you guessed it, only the last name appears.

The solution is to nest the elements in one frame. Here’s how you do it:

  1. Select the Text tool.

  2. Select the placeholder for the first name.

  3. Click Efirstname in the Tags panel.

    The placeholder displays tag brackets for the Efirstname element.

  4. Tag the last name placeholder with Elastname.

    The layout is completely tagged (Figure 4.42), but we’re not quite done yet.

    The frames-based layout looks similar to the text-based method, except that the tags are applied to the frames instead of the text.

    Figure 4.42. The frames-based layout looks similar to the text-based method, except that the tags are applied to the frames instead of the text.

  5. Save file as mycardtest1.indd.

Lesson 4-15: Modifying Element Order

Observe the hierarchy of the elements (Figure 4.43). Hopefully, you recognize at least four problems in the structure. First, the root element is named incorrectly. Second, the elements are not in the same order as they appear in the XML file itself. Third, the dreaded “Story” element seems to have reared its ugly head again. And fourth, there is no employees element at all.

Study the Structure pane carefully. Note the order of the elements and how they are nested. Usually, the first sign of trouble can be seen here.

Figure 4.43. Study the Structure pane carefully. Note the order of the elements and how they are nested. Usually, the first sign of trouble can be seen here.

The first two problems are solved easily:

  1. Select the Root element in the Structure pane.

  2. Click dataroot in the Tags panel (Figure 4.44).

    Changing the name of an element can be done quickly and painlessly within the Structure pane.

    Figure 4.44. Changing the name of an element can be done quickly and painlessly within the Structure pane.

    The Root element is renamed dataroot. One problem solved.

  3. Select the Story element in the Structure pane.

  4. Drag the Story element to the top of the list, just below dataroot (Figure 4.45).

    It takes a calm hand, keen eye, and practice to be able to move critical elements within the structure correctly. Always check the results before you proceed to the next task. As you have already seen, the success of your XML workflow depends upon it.

    Figure 4.45. It takes a calm hand, keen eye, and practice to be able to move critical elements within the structure correctly. Always check the results before you proceed to the next task. As you have already seen, the success of your XML workflow depends upon it.

    The Story tag and the placeholders for Efirstname and Elastname have moved to the top of the list.

Lesson 4-16: Renaming Structural Elements

Two problems have been solved, but the presence of the Story element and lack of an employees element have effectively broken our structure.

Here’s a partial solution to the dilemma that doesn’t require reconstructing the XML file itself:

  1. Select the Story element in the Structure pane.

  2. Click employees in the Tags panel.

    The Story element has been renamed employees.

Simply renaming the Story element hasn’t entirely fixed our problem. Follow along and watch carefully:

  1. Select dataroot in the Structure pane.

  2. Import employees.xml. Select only the following import options:

    • Clone repeating text elements

    • Only import elements that match existing structure

    • Do not import contents of whitespace-only elements

Lesson 4-17: Troubleshooting XML Structure

Observe the results of the import (Figure 4.46). Only the first and last names imported correctly. Look at the Structure pane. See how the imported content inserted itself between the first employees element and the placeholders for Etitle, Ephone, and Eemail? Because the placeholders were not part of the employees element, they were ignored when the XML was imported.

The first and last name imported correctly, but where’s the rest of the data? See how the faulty structure caused the XML to ignore the placeholders for the title, phone number, and email address.

Figure 4.46. The first and last name imported correctly, but where’s the rest of the data? See how the faulty structure caused the XML to ignore the placeholders for the title, phone number, and email address.

As we explained in Chapter 1, proper XML structure is ignored at your peril. Here’s a simple fix to this problem:

  1. Select Undo from the Edit menu.

    The layout returns to the previous state: The XML content is purged from the Structure pane and the generic First and Last name placeholders are restored.

  2. Drag the Etitle element into the employees element in the Structure pane (Figure 4.47).

    Creating the proper structure may take several steps. Here we dragged the Etitle element into the employees element (left). It appears in the wrong position of the structure (middle). So, we move it to its proper location (right).

    Figure 4.47. Creating the proper structure may take several steps. Here we dragged the Etitle element into the employees element (left). It appears in the wrong position of the structure (middle). So, we move it to its proper location (right).

    The Etitle element appears as a child element of employees.

    Very important: Note that the actual placement of the placeholder on the layout has not changed.

  3. Drag the Etitle element below Elastname in the Structure pane.

    Etitle now appears in its proper location within the XML structure.

  4. Repeat steps 2 and 3 with the Ephone and Eemail elements.

    The placeholder structure now mimics the desired XML structure.

  5. Select File > Save.

    Let’s try importing the XML file again:

  6. Select dataroot and import employees.xml.

    • The XML content imports successfully this time.

    • All placeholders are properly replaced and display the expected data from the XML file.

Lesson 4-18: Creating Multiples

You may be thinking right now that all looks well with our current document and you’re finished—but this isn’t called the “wrong way” for nothing. Although the content imported correctly into the placeholders on page 1, you’re going to have problems generating cards for the remaining five employees. Although you will have to backtrack a little when it fails, let’s take a look at what happens:

  1. Drag A-Master to the Page panel to create a new page.

  2. Display page 2.

  3. Drag the employees element for the second employee to page 2.

    All the information for the second employee appears in a single text frame (Figure 4.48).

    When you try to flow one of the other records into the layout InDesign doesn’t clone the individual structured frames from page 1. And there’s no way to make it do so short of scripting or third-party plug-ins.

    Figure 4.48. When you try to flow one of the other records into the layout InDesign doesn’t clone the individual structured frames from page 1. And there’s no way to make it do so short of scripting or third-party plug-ins.

    Now you know why it’s called the wrong way. Without scripting or third-party plug-ins, there’s no way (that we know of) to get InDesign to create multiple pages automatically from the structured layout as it appears after step 4 in Lesson 4-17. It is possible to create all six cards, just not automatically as you did in our other method.

    This is what you have to do to automate the process to build multiples:

  4. Select File > Revert.

    The XML content disappears from the Structure pane and the tagged placeholders revert to their appearance after Lesson 4-17, step 5.

  5. Select page 1 in the Pages panel.

  6. Select Duplicate Spread from the Pages panel menu (Figure 4.49).

    By using the existing structured layout on page 1 to create a new page, instead of the A-Master, you can get around the cloning problem.

    Figure 4.49. By using the existing structured layout on page 1 to create a new page, instead of the A-Master, you can get around the cloning problem.

    A duplicate page appears in the panel, which includes all the placeholders as in page 1.

  7. Observe the Structure pane (Figure 4.50).

    After duplicating page 1, as you can see here, an unwelcome surprise is waiting for you in the Structure pane. For some unknown reason, the Etitle, Ephone and Eemail elements from page 2 are nested within the employees element on page 1.

    Figure 4.50. After duplicating page 1, as you can see here, an unwelcome surprise is waiting for you in the Structure pane. For some unknown reason, the Etitle, Ephone and Eemail elements from page 2 are nested within the employees element on page 1.

    STOP! Do you see what just happened? When you duplicated page 1, InDesign did as you asked and then promptly screwed up the perfectly good structure. This is the real kicker: If you look at page 2, you see the exact same placeholders as on page 1, which is great. But a glance at the Structure pane tells you that the page 2 title, phone, and email placeholders were incorporated into the page 1 employees element! Egads!

    You know enough about XML by now to know that this won’t fly. If you don’t fix this problem, the imported XML will ignore the title, phone, and email placeholders on page 2 as it did after Lesson 4-16, step 4.

    Here’s how you can once again rescue this errant structure:

  8. Select one Etitle, Ephone, and Eemail element from the Structure pane. Hold Shift to select consecutive elements, or Cmd (Ctrl) to select non-consecutive elements.

  9. Drag the selected elements below Elastname in the second employees element in the Structure pane (Figure 4.51).

    Although it’s an added step, it’s easy to Shift-select all three elements and drag them down to where they belong. You will have to do the same manual troubleshooting for any new page you want to create.

    Figure 4.51. Although it’s an added step, it’s easy to Shift-select all three elements and drag them down to where they belong. You will have to do the same manual troubleshooting for any new page you want to create.

    The three elements now appear as child elements in the correct position in the structure (Figure 4.52).

    Finally, both pages display properly structured layouts that are ready for XML.

    Figure 4.52. Finally, both pages display properly structured layouts that are ready for XML.

Lesson 4-19: Payoff = Unlimited Possibilities

To create sufficient pages for the six new employees, you have to repeat steps 5–9 in Lesson 4-18 four more times. It’s a lot of extra work for what seems to be no reward at all. But, there’s a potential advantage to using the floating frames method that you may not see yet. Before you import the XML try this:

  1. Reposition the placeholders in your layout; see Figure 4.53 for one suggestion.

    Once you’ve created a valid structure, have fun with your floating frames. This screenshot gives you one suggestion.

    Figure 4.53. Once you’ve created a valid structure, have fun with your floating frames. This screenshot gives you one suggestion.

    You can put the placeholders literally anywhere on the card as long as the elements stay in the proper order within the Structure pane.

    Now you can import the XML file:

  2. Select dataroot and import employees.xml.

    The XML imports properly into all the cards no matter where you positioned the placeholders. In fact, each of the six cards can feature individualized designs.

You’ll have to decide whether this little bit of design flexibility is worth all the effort. It certainly isn’t to us. But there are some valuable lessons in the following review section to take away from this vain procedure nonetheless.

Review

  • InDesign can import XML content into any properly structured layout.

  • InDesign cannot clone the position and formatting of independent text frames without a lot of manual assistance.

  • The actual position of a placeholder frame on the page is irrelevant to its position within the Structure pane.

  • Elements can be manually rearranged in the Structure pane to conform to the desired XML structure.

In most cases, structured layouts will put a crimp in your “creative” expression no matter what you do. So the one aspect we like about this frame-based method is that it allows more freedom to “design” a layout. Understanding the structure and knowing how to control the flow of data onto the page can vastly expand your XML capabilities.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.34.205