Skip to main content
Advice

Export content from InDesign and deliver it to your digital service

Dan BadhamFront-end developer and designer
8 min read27 March 2018

We all use a variety of systems on a daily basis. You might have content in a catalogue system, a learning management system, or publishing software. When you want to use this content elsewhere – say on your website, in an app, or in printed material – you probably have to resort to copying and pasting content from one system to another.

Download the source code from GitHub
XML
1
2
3
4
5
6
7
8
9
10
11
12
13
<!ELEMENT Cover (CoverTitle,CoverSubtitle)> <!ELEMENT CoverTitle (#PCDATA)> <!ELEMENT CoverSubtitle (#PCDATA)> <!ELEMENT Stories (Story*)> <!ELEMENT Story (StoryHeading*,StoryIntroduction*,StorySubHeading*,StoryText*,StoryImage*,StorySubHeading*,StoryImage*,FeatureImage*)*> <!ELEMENT StoryHeading (#PCDATA)> <!ELEMENT StoryIntroduction (#PCDATA)> <!ELEMENT StoryText (#PCDATA)> <!ELEMENT StorySubHeading (#PCDATA)> <!ELEMENT StoryImage EMPTY> <!ATTLIST StoryImage href CDATA ""> <!ELEMENT FeatureImage EMPTY> <!ATTLIST FeatureImage href CDATA "">
C#
1
2
3
4
// Create the management client var client = ManagementClient.Create("[ADD CMS URL HERE]", "[ADD YOUR API CLIENT ID HERE]", "[ADD YOUR API SHARED SECRET HERE]");
C#
1
2
// Get the project var project = client.Projects.Get("[ADD YOUR CONTENSIS PROJECT NAME HERE]");
C#
1
2
// Load the XML file into an XElement XElement doc = XElement.Load(@"C:\Sites\indesign-import-to-contensis\dotnet-xml-import\XMLImport\finalXML.xml");
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Load the XML file into an XElement XElement doc = XElement.Load(@"C:\Sites\indesign-import-to-contensis\dotnet-xml-import\XMLImport\finalXML.xml"); // Navigate the XElement to create the stories IEnumerable<Story> stories = (from x in doc.Descendants("Stories").Elements("Story") select new Story { Title = x.Element("StoryHeading").Value, Introduction = x.Element("StoryIntroduction").Value, StoryBody = x.Element("StoryBody").Elements() }).ToList(); // Local testing in console //Console.WriteLine("Story title: " + stories.First().Title); //Console.WriteLine("Story Intro: " + stories.First().Introduction); //Console.WriteLine("Story Body: " + stories.First().StoryBody); //Console.ReadLine(); // Iterate through stories and call entry creator foreach (var story in stories) { CreateEntryFromXML(project, story); }
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Create entries private static void CreateEntryFromXML(Project project, Story story) { // Set-up a new story entry var storyEntry = project.Entries.New("story"); var composer = new ComposedField(); string html = ""; foreach (XElement el in story.StoryBody) { html = html + ElementCleaner(el); } byte[] bytes = Encoding.Default.GetBytes(html); html = Encoding.UTF8.GetString(bytes); composer.Add(new ComposedFieldItem("storyMarkup", html)); storyEntry.Set("storyComposer", composer); // Set each field value storyEntry.Set("title", story.Title); storyEntry.Set("subtitle", story.Introduction); // Save and publish the story storyEntry.Save(); storyEntry.Publish(); Console.WriteLine({{APP}}quot;Saved story {storyEntry.Get("title")}"); }
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
private static string ElementCleaner(XElement el) { string s = ""; switch (el.Name.LocalName) { case "StoryText": s = "<p>" + el.Value + "</p>"; break; case "StorySubHeading": s = "<h2>" + el.Value + "</h2>"; break; } return s; }
Dan BadhamFront-end developer and designer

Ready to get started?

Contensis supports modern development practices. And it works with your preferred tools – from VS Code to Git. Browse the documentation to get started.

Request a demo