xml problems
I need some XML help.
I have data in excel that I need to convert to XML in a particular way, making one column a property of another column.
In this particular case, converting it to XML isn't really the problem; that's done already. The program I'm trying to use this data with does that for me already. What I'm having trouble with is working around a problem that requires me to insert two properties in a tag. I'll give an example:
I have these fields (in excel and in the XML file)...
<myfield1>some data</myfield1>
<myfield2>some data 2</myfield2>
What I need is the following (approximate, I don't remember the exact syntax I need):
<myfield1 property="SomeStaticText" property2="some data 2">some data</myfield1>
How in the world can I do that without having to do it manually?
And once we're on the topic of XML, does anyone have a program they can recommend? Mac or PC at this point.... I can't find anything easy/simple to create XML files and excel seems to export one heck of a mess for XML.
Thanks
I have data in excel that I need to convert to XML in a particular way, making one column a property of another column.
In this particular case, converting it to XML isn't really the problem; that's done already. The program I'm trying to use this data with does that for me already. What I'm having trouble with is working around a problem that requires me to insert two properties in a tag. I'll give an example:
I have these fields (in excel and in the XML file)...
<myfield1>some data</myfield1>
<myfield2>some data 2</myfield2>
What I need is the following (approximate, I don't remember the exact syntax I need):
<myfield1 property="SomeStaticText" property2="some data 2">some data</myfield1>
How in the world can I do that without having to do it manually?
And once we're on the topic of XML, does anyone have a program they can recommend? Mac or PC at this point.... I can't find anything easy/simple to create XML files and excel seems to export one heck of a mess for XML.
Thanks
Comments
What you want is an XSLT. It's a ruleset for converting XML formats, and can easily handle what you want. Non-trivial though. You'll also need to get an XSLT engine. I use xsltproc, a command line tool.
You guys scared me pretty good with the XSLT stuff. I looked into it, downloaded programs and gave up. I figured it would be faster to do it by hand than to learn what I needed.
Using my favourite method of solving problems, the kludgy work-around, I think I solved this.
All my data is in excel so I can create a new field that looks like this:
parameter="1000-2000" format="static text"abc123
The 1000-2000 and the abc123 are pulled from other cells so that's easy to do, just one formula with lots of quotation marks
I import that data into the program then asked it to export an XML file for me.
I now have a field that looks like this
<my_field>parameter="1000-2000" format="static text"abc123</my_field>
I open the XML file in BBEdit and do two find&replaces'.....
<my_field>parameter -> <my_field parameter
format="static text" -> format="static text">
my line now looks like this:
<my_field parameter="1000-2000" format="static text">abc123</my_field>
which is exactly what I wanted.
Other than having to wait for data to import and export a few extra times it's pretty quick and painless.... assuming BBEdit is ok with 50mb file (i've yet to test that part but I don't anticipate a problem doing the search and replace). I can use smaller pieces if need be.
Thanks for the suggestions though. If I wasn't scared off with the XSLT stuff I might never have found the easier solution (easier for me anyway)