Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML output

Status
Not open for further replies.

jmanj

Programmer
May 20, 2003
298
US
Does anybody has a sample or how-to procedure on
creating a simple xml output from csv input file?

Thanks for any help.
 
Get schema or DTD to create output tree, Map as required.



JuJutsu - Jeff S.
Support Analyst
 
So here's what I did :
1. Create a csv file with two field headers:
Name,Age
John A,21
John B,21
Johnny Appleseed,18
Johnny Walker,65
Joe Nobody,85

2. I created a DTD based on above (hope I'm right)

<!-- Defines a Sample (PA) Document -->

<!-- The root of the document -->
<!ELEMENT PA (Header)*>

<!ELEMENT Header (Name, Age,)>

<!ELEMENT Name (#PCDATA)>
<!ELEMENT Age (#PCDATA)>

3. I imported the DTD to mercator and it created an XML typetree.

Question: 1. Do I have to use the created typetree as both
input and output(XMLDATA)and have my csv file as the
source data?

2. Do I have to create a separate tree for the csv file with the headers(1:1) and data(s) as separate records?

Note: I have only done simple mapping in mercator but I have no idea how to map to an xml data.

Thanks for any help.
 
Hi,

Step1: Create an input tree for reading csv file.
step2: Use the tree which you have imported from DTD as output tree.

Now you can start mapping. This map will convert your csv to xml
 
Samji is correct, create a functional map and just drag and drop the appropriate elements, and the tree will create the tags.



JuJutsu - Jeff S.
Support Analyst
 
I have created a typetree for the csv file as input and used the xml type tree created from DTD as output. Still I'm having
problem mapping the header(1:1) and the data (s). It's been a long time since my last mapping program so bear with me.

Thanks for the hints. Any more hints on mapping will be appreciated.
 
We have an older version of Excel (2000) so there is no way for me to create xml file from excel. Is there tools or a way to create the DTD from excel? The above dtd sample I created manually using notepad. Is there a better way?

Thanks.
 

I tried to map in the following way.

1. Input tree:

Check the delimiters and terminators ..very important or else it will fail to validate your input file and hence the map will not run and throws input invalid.


2. Output tree.

creating dtd:

There are some tools for crreating dtd's but I am not aware of them, I have done it manually.

<!ELEMENT Sample (PA+) >
<!ELEMENT PA (Header,message) >

<!ELEMENT Header (name,age) >

<!ELEMENT message (Data*) >
<!ELEMENT Data (name,age) >

<!ELEMENT name (#PCDATA) >
<!ELEMENT age (#PCDATA) >

<!ATTLIST Sample VERSION (1) #REQUIRED >

<!ATTLIST PA BEGIN (1) #REQUIRED >

<!ATTLIST Header SEGMENT (1) #REQUIRED >

<!ATTLIST message BEGIN (1) #REQUIRED >
<!ATTLIST Data SEGMENT (1) #REQUIRED >


The fields for header can be changed. Here I just used the same elements that are used for data.



Step 2 Mapping:

In the output card, perform mapping under Global/ ElemDecl PA
In that you find Header and data.
Do one to one mapping for header and create a functional map for Data under seq(s)

When I do mapping I got output something like this

- <PA BEGIN="">
- <Header SEGMENT="1">
<name>name</name>
<age>age</age>
</Header>
- <message BEGIN="1">
- <Data SEGMENT="1">
<name>John A</name>
<age>21</age>
</Data>
- <Data SEGMENT="1">
<name>John B</name>
<age>21</age>
</Data>
- <Data SEGMENT="1">
<name>Johnny Appleseed</name>
<age>18</age>
</Data>
- <Data SEGMENT="1">
<name>Johnny Walker</name>
<age>65</age>
</Data>
- <Data SEGMENT="1">
<name>Joe Nobody</name>
<age>85</age>
</Data>
</message>
</PA>

I am not very sure whether you are looking for something similar.



 
Samji,

Thanks for the valuable posting. I will try to follow your way and see if I can map it correctly. By the way my Mercator is version 5.0. I hope this will work. I was told that we need to map a csv file into xml. I have not seen the full spec yet but I'm getting ready just in case.
 
Samji,

I created the dtd from your example and imported to mercator.
It created a typetree perfectly but I cannot find
Global/ ElemDecl PA groups or categories at all.

Could this be difference in version? I'm working on mercator 5.0. Still struggling with the mapping part.
 
Hi,

I done this in 7.5. The imported tree is generated for 6.7 and higher versions. Definetely this structure will be different from that of 5.0. But I think that will not be a problem while mapping.

But any ways I will try in 5.0 and check the result and update you.


 
Hi,


It works fine in mercator 5.0 also.
Import the same dtd in 5.0. The tree will contain xml as root and also you can find the
categories like #CHILD DATA, #CONTENT,#DATA ..., document,etc.

Now in the map you can select Document as the type for the output card.
In the output card you can see prolog and Sample element.

Prolog contains all the xml declarations like version,encoding, standards.
You can fill them later but for now keep them to NONE.

Prolog(0:1) = NONE

Sample element:

Version = 1.0
And create a functional map for PA element which is under Sample child data.

In the functional mapping you again find PA attlist, it contains the begin attribute ..map it to 1.
In this functional map you find both header and data part. Do one to one mapping for header and create a functional map for DATA part.

The output looks like this.

- <Sample VERSION="1.0">
- <PA BEGIN="1">
- <Header SEGMENT="1">
<name>Name</name>
<age>Age</age>
</Header>
- <message BEGIN="1">
- <Data SEGMENT="1">
<name>John A</name>
<age>21</age>
</Data>
- <Data SEGMENT="1">
<name>John B</name>
<age>21</age>
</Data>
- <Data SEGMENT="1">
<name>Johnny Appleseed</name>
<age>18</age>
</Data>
- <Data SEGMENT="1">
<name>Johnny Walker</name>
<age>65</age>
</Data>
- <Data SEGMENT="1">
<name>Joe Nobody</name>
<age>85</age>
</Data>
</message>
</PA>
</Sample>





 
FYI, Version 5.x was sunsetted three years ago. There have been many fixes (especially to XML) since then. Suggest you contact sales person and begin making plans to upgrade to 8.0 (due out next month). If you find a bug in 5.x, you are up the creek without a paddle, or a boat.



JuJutsu - Jeff S.
Support Analyst
 
Samji,

Still agonizing but getting close. This time I could not map
the begin attribute(under PA attlist) to 1.

Here's what I did.

1. Create output card using Document group.
set Prolog(0:1) = NONE
set VERSION = 1.0 in Sample element

2. Create another functional map(PAELEM) in PA element(1:s) which is under Sample #CHILDDATA
3. In PAELEM card I used PA group under Attlist category and
here's where I cannot map BEGIN attribute to 1. It's giving me an error.


In the first output card (Document) It does'nt give me option to map header and data part(grayed out). Am I in the right direction? Thanks very much.
 

In the PAELEM functional map:

1. Expand PA Attlist. You see BEGIN PA Attlist, expand that you fing Begin value..map that to "1"

Note:

In the XML structure you always find two subsections one attribute list and one child data

Generally in att you find feilds like begin, segment ,etc
and in child data you find actual data.

2. Now expand PA#CHild data.keep on expanding till you find segment header under Header attlist then under child data
you can find name and age elements..map them.

3. You can also see in the same card the Message elemnt.
It also has Begin and Child data(s)
Map begin value to "1" and create a functional map for Data elements.

 
Samji,

Still having errors in my functional map:

M114 ERROR:
Map: Records Output: PA Element:Sample #CHILDDATA:Sample #CONTENT:Card2
Output argument of rule does not match output type:
=PAElem(Name:Data,Age:Data)


Is PA Element(1:s) the right item to put the functional map?
 
Samji,

I think I got it. I have my first output same as your output. However, my output is in one long string. Is there a way or do I have to change something(DTD?) so that it will have a line
by line output?

Thank you very many.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top