I am trying to convert a bunch of text files into structured XML files. Using string expressions I have extracted data, so I have:
title={"https://www.ometz.ca/event/abiletes-dentrevue-1-678/?langID=1"};`
date={2011,7,14,13,22,22.`};`
content=": text/html; charset=UTF-8 Ometz A community of services for life Employment Job Seekers Job Listings Job Seeker Registration Career Counselling Employers Cocktails & Conversation Candidate Profiles Employers - Submit a Job Posting ProMontreal Entrepreneurs Fund ProMontreal Entrepreneurs Mentors Calendar You & Yours Community Assistance Counselling Services Administered Funds Orthodox Community We";`
So far I have done the following to generate XML objects, for title, date, and content in turn. It is a bit messy but seems to work.
a = ExportString[
XMLElement[
"title", {}, {StringReplace[
ToString[title], {"{" -> "", "}" -> ""}]}], "XML"]
b = ExportString[
XMLElement[
"date", {}, {StringReplace[
ToString[date], {"{" -> "", "}" -> ""}]}], "XML"]
c = ExportString[XMLElement["body", {}, {content}], "XML"];
The output is thus:
<title>https://www.ometz.ca/event/abiletes-dentrevue-1-678/?langID=1</title>
<date>2011, 7, 14, 13, 22, 22.</date>
<body>: text/html; charset=UTF-8 Ometz A community of services for life Employment Job
Seekers Job Listings Job Seeker Registration Career Counselling Employers Cocktails &
Conversation Candidate Profiles Employers - Submit a Job Posting ProMontreal Entrepreneurs
Fund ProMontreal Entrepreneurs Mentors Calendar You & Yours Community Assistance
Counselling Services Administered Funds Orthodox Community We</body>
So far so good, but I need to get it exported to an XML file, say text.xml
.
For some reason I'm hitting a wall in how to get this working, despite reading docs & some supplementary material. How would you do this? (also, any advice on the above code is appreciated)
Export
? $\endgroup$Export["file.xml", string, "Text"]
which won't escape the brackets. However, once you have a root element, I suggest crafting anXMLObject
and build your document inside it. Then, you canExport
it with ease. Also, look at this tutorial. $\endgroup$