Video: Exporting to XML

I have opened ChocolateSheet5 from the Exercise Files, and this is a clean document, not the template we were working on in earlier movies. You can see that in the Tags panel, we don't have any tags in here, there is no tags applied to objects in the document at all. So we have been given the task of exporting this content as XML. Now, I do want to be clear that in general I recommend having InDesign be a container for receiving XML rather than a source of exporting XML. It's cleaner to start with your XML outside of InDesign and then drop it into an InDesign template as we saw in the last few movies, but if you do need to get your content out of a document here is what you can do.

David Blatner brings his knowledge of and passion for InDesign to the latest release of this state-of-the-art publishing program, showing how to harness its power and functionality. InDesign CS4 Beyond the Basics covers the process of publishing with an eye on the program's latest nuances: optimizing page layouts, automating InDesign with Data Merge and XML, exploring interactive documents (including making movies), and exporting publications to a variety of formats. Exercise files accompany the course.

Exporting to XML

I have opened ChocolateSheet5 from the Exercise Files, and this is a cleandocument, not the template we were working on in earlier movies. You can seethat in the Tags panel, we don't have any tags in here, there is no tagsapplied to objects in the document at all. So we have been given the task ofexporting this content as XML.Now, I do want to be clear that in general I recommend having InDesign be acontainer for receiving XML rather than a source of exporting XML. It's cleanerto start with your XML outside of InDesign and then drop it into an InDesigntemplate as we saw in the last few movies, but if you do need to get yourcontent out of a document here is what you can do.

The first thing we need is tags. I could make them one at a time, as we saw inan earlier movie, but I am just going to import them using Load Tags. I amgoing to just select this XML file that I have inside of the Exercise Filesthat has all of the tags in it.Now I am going to tag these objects in my document, just like I did in earliermovies. I will select this head at the top and I will click on Header. I willselect the story here and click on story. I will click the subhead here, and Ibelieve this is called caption. There we go. That's supposed to get the captiontag. Now let's get those images: Number 1 and Number 2.

Let's view the structure in the Structure Pane by pressing Cmd+Opt+1 orCtrl+Alt+1 on Windows, and I will twirl down this little triangle here to seethe structure here.Now, I do remember that in the XML file I want, in the structure that I want, Iwant to put the caption between the two images; I just remembered that, so Ibetter just drag that down to put it in the right order.Now, inside this story, this text frame or this text thread that I tagged withthe story tag, we have multiple paragraphs. In fact, if I zoom in here withCmd+2 or Ctrl+2 on Windows, we can see that not only do we have multipleparagraph styles, we also have character styles in here as well. But all I didwas apply the story tag to the whole thing.

Well, in order to tag the paragraph and the character styles in here properly Ineed to map those character styles and paragraph styles to proper tags in theXML. The way I am going to do that is to go to the Tags panel flyout menu, andchoose Map Styles to Tags. That's different than what we saw before, before wemapped tags to styles, now we are mapping styles to tags.Now, in this case I am only going to be mapping the tags for these paragraphand the character styles, and I happen to know that that is the Body Paragraphsstyle, and I am going to map that to bodytext tag in the XML. Also, the Italiccharacter style should map to emphasis.

When I click OK, you can see -- well, it's a little hard to see, but there'slittle yellow tags around the italic text here, and that yellow is the emphasistag has been applied.Over in the Structure panel I can see that I have some extra twirly triangleshere, and if I click on those, I can see all of the different paragraphs thathad been affected here. They have all been tagged and if I look inside thisbodytext paragraph, there is the emphasis tag.Another way to see the structure of this story is to look at it in StoryEditor. So while this is selected on the Document Page, I am going to go toEdit and choose Edit in Story Editor. Story Editor is a wonderful way to lookat tagged text, because it's much easier to see things like, that's emphasistext, than it is to look for these little tiny brackets on the page here.

We can also apply tags here. For example, I will just select these four wordshere and click on the emphasis tag, and you can see that it shows up here, andit shows up as tagged down here.What's more, if we look at our Structure Pane, we see that we have one moreemphasis tag in the structure as well.Okay, now that we have everything tagged, let's go ahead and export the XML. I am going to export the entire document here as XML by choosing Export XML fromthe Structure panel menu. Another way to do this would be to choose Export fromthe File menu and just do the normal export dialog box route; both do exactlythe same thing.

We will name it here; tell it where to save the XML file. Click Save, and wewill see the Export XML dialog box. I am not going to go through all of theseoptions right now, because they get kind of technical, but I will tell you theones that are most important.First of all, we are going to view the XML after its exported using whateverapplication you want to use. I have a text editor on the Mac here calledTextWrangler. This is my favorite text editor on the Mac, its a free texteditor, and it works really well for viewing text, so that's what I have chosenhere. But if you have another application that handles XML or text, you canchoose it from this pop-up menu.

We are going to be Exporting From the Selected Element here. Because we haveselected Root, so we are just going to grab the entire thing. If we had Tablesthen we might want to export them as CALS XML, but I am not going to worryabout that now, I have no tables in here.Now, Remap Break, Whitespace, and Special Characters is important in myexperience, because InDesign seems to put in a lot of weird characters in theXML, and sometimes that can really mess up a text editor or an XML Editor, so Irecommend that you always Remap those Break, Whitespace, and Special Charactersto other characters in the XML, it's just safer that way.

In an earlier movie I was talking about XSLT and how it's like a superchargedFind/Change feature. If you have an XSLT that you want to use, you can Apply ithere upon export, and all of your XML will be pushed through that Find/Changerthing and it will turn into something different, whatever the XSLT tells it to do.XSLTs are quite powerful. You can turn almost anything into anything else. Forexample, I have seen XSLTs that will take regular XML and convert it into HTML,so that would be an option here for your XML.

I also want to point out, there is an Images tab of the Export XML dialog box,and this gives you control over how you want your images to be exported.Typically, you just get an XML file, just the text file, but if I turn on anyof these checkboxes then I actually get the images themselves inside an ImagesSubfolder; it will copy them into an Images Subfolder for me. That could beuseful in certain circumstances.The Original Images, it's obvious it just copies the entire original image: thePhotoshop files, or TIFFs or JPEGs or whatever. But Optimized Original Imagewill actually convert those images into JPEGs and GIFs for me.

I have to tell you, I am not a fan of this. I personally feel like Photoshopwould be a better tool, or Fireworks, or almost anything else would be a bettertool than InDesign for converting images into GIFs or JPEGs, so I don't use that.But I will point out that if you are going to do it, you might want to use thisOptimized Formatted Images option instead, because that will actually crop andscale and rotate and whatever. It will format those images and then convertthem to JPEGs or GIFs on the fly.So in this case, I don't want any of those images, I just wanted to let youknow that that was an option.

I am going to click Export, and it will export the XML and open it up in thetext editor, in this case TextWrangler. If you squint here you can really seethat all of the data is there: the headers and the story and the emphasisinformation, and so on and so on, it's all there, including the graphics and theimages at the end, and so on.Now, just because I have exported XML successfully from InDesign doesn't meanthat I can turn around and reimport it back into InDesign. That's called roundtripping. While it is possible to round-trip your XML in some situations,I have to tell you that in most cases it won't work right without somesignificant massaging. In fact, in general, you should probably expect to dosome cleanup of InDesign's XML files, whether this is headed to the web or to adatabase or back into some other InDesign template.

Nevertheless, the ability to get XML out of InDesign can be incredibly useful,especially in a fast-paced production environment, where you need to repurposeyour content everyday.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.

Already a member ?

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships.
Learn more

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.

Sign up and receive emails about lynda.com and our online training library:

new course releases

newsletter

general communications

special notices

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

new course releases

newsletter

general communications

special notices

Here’s our privacy policy with more details about how we handle your information.