Re: [Servingxml-help] pos file repeating sections to nested XML
Brought to you by:
danielaparker
|
From: Brewer, K. <ken...@pe...> - 2005-11-26 19:15:06
|
Thanks for such prompt response and solution! I'll try the new release. The
workaround script you provided worked perfectly. That leads to me another
question - big surprise huh. What if there are multiple repeating sections
scattered throughout the record - how do I specify how many times it repeats
or where it ends and regular fields start again?
Here's an example of the record with some attempted ascii-art
annotation(view with non-truetype font), the actual record begins with
'JANE'.
S |
T |
R |
U |
C |
T |-----------------------------------------
U || |(repeating)| | |(repeating)
R || |-----------| | |----------------
E || | | | | | | | | | |
--|JANEENGLC-MATHA+1972BLUECHICAGOILATLANTAGA
F || | | | | | | | | | |
I |N S G S G Y C C S C S
E |a u r u r e o i t i t
L |m b a b a a l t a t a
D |e j d j d r o y t y t
S | e e e e B r e e
| c c o
| t t r
| n
example disired output:
<StudentGrades>
<StudentGrade>
<Name>JANE</Name>
<SubjectGrade>
<Subject>ENGL</Subject>
<Grade>C-</Grade>
</SubjectGrade>
<SubjectGrade>
<Subject>MATH</Subject>
<Grade>A+</Grade>
</SubjectGrade>
<YearBorn>1972</YearBorn>
<Color>BLUE</FavoriteColor>
<Address>
<City>CHICAGO</City>
<State>IL</City>
</Address>
<Address>
<City>ATLANTA</City>
<State>GA</City>
</Address>
</StudentGrade>
<StudentGrade>
<!-- this 2nd record omitted for brevity -->
</StudentGrade>
</StudentGrades>
Thanks again,
-Ken
> This issue reported below has been fixed in 0.3.1b. You can download it
> from here:
> http://sourceforge.net/project/showfiles.php?>
group_id=95689&package_id=102046&release_id=369842
> An example resources-students.xml script has been added to the flatfile
> samples.
> Regards,
> Daniel Parker
----- Original Message -----
From: "Daniel Parker" <dan...@sy...>
To: "Brewer, Ken" <ken...@pe...>;
<ser...@li...>
Sent: Friday, November 25, 2005 11:59 PM
Subject: Re: [Servingxml-help] pos file repeating sections to nested XML
> Hello Ken,
>
> Thanks for the feedback, the support for repeating groups is quite new, so
> I'm pleased that it's being exercised.
>
> The resources script should look like this:
>
> <?xml version="1.0"?>
> <sx:resources xmlns:sx="http://www.servingxml.com/core">
>
> <sx:service name="students">
> <sx:serialize>
> <sx:transform>
> <sx:content ref="students-content"/>
> </sx:transform>
> </sx:serialize>
> </sx:service>
>
> <sx:recordContent name="students-content">
> <sx:flatFileReader>
> <sx:urlSource url="data/students.txt"/>
> <sx:flatFile ref="students-file"/>
> </sx:flatFileReader>
> <sx:recordMapping ref="students-mapping"/>
> </sx:recordContent>
>
> <sx:flatFile name="students-file">
> <sx:flatFileBody>
> <sx:flatRecordType name="student">
> <sx:positionalField name="name" width="4"/>
> <sx:repeatingGroup>
> <sx:flatRecordType name="subject-grade">
> <sx:positionalField name="subject" width="4"/>
> <sx:positionalField name="grade" width="1"/>
> </sx:flatRecordType>
> </sx:repeatingGroup>
> </sx:flatRecordType>
> </sx:flatFileBody>
> </sx:flatFile>
>
> <sx:recordMapping name="students-mapping">
> <StudentGrades>
> <sx:onRecord>
> <StudentGrade>
> <sx:fieldElementMap field="name" element="Name"/>
> <SubjectGrade>
> <sx:onRecord>
> <sx:fieldElementMap field="subject" element="Subject"/>
> <sx:fieldElementMap field="grade" element="Grade"/>
> </sx:onRecord>
> </SubjectGrade>
> </StudentGrade>
> </sx:onRecord>
> </StudentGrades>
> </sx:recordMapping>
>
> </sx:resources>
>
> However, you've uncovered a bug. The name field appearing before the
> repeating group is being skipped. There is a workaround - you can get
> this to work by enclosing the student record type definition in an
> sx:flatRecordTypeChoice, with one choice, like this:
>
> <sx:flatFile name="students-file">
> <sx:flatFileBody>
> <sx:flatRecordTypeChoice>
> <sx:positionalField name="name" width="4"/>
> <sx:when test="1=1">
> <sx:flatRecordType name="student">
> <sx:positionalField name="name" width="4"/>
> <sx:repeatingGroup>
> <sx:flatRecordType name="subject-grade">
> <sx:positionalField name="subject" width="4"/>
> <sx:positionalField name="grade" width="1"/>
> </sx:flatRecordType>
> </sx:repeatingGroup>
> </sx:flatRecordType>
> </sx:when>
> </sx:flatRecordTypeChoice>
> </sx:flatFileBody>
> </sx:flatFile>
>
> I've tested this this and it works (it's now like the comptest example,
> which does work.)
>
> I'll have a fix for the straightforward implementation soon, and add your
> example to the examples in the documentation.
>
> -- Daniel
>
>
> ----- Original Message -----
> From: "Brewer, Ken" <ken...@pe...>
> To: <ser...@li...>
> Sent: Friday, November 25, 2005 10:15 PM
> Subject: [Servingxml-help] pos file repeating sections to nested XML
>
>
>> I'm new to serving xml, it's quite impressive, thanks!
>>
>> I'm trying convert a fixed width(positional) flat file, with repeating
>> groups, to XML with nested elements. Can serving xml do this? I've made
>> several attempts based on some of the examples but I still haven't been
>> able
>> to get the desired output.
>>
>> The flat file looks like this:
>>
>> JANEENGLCMATHA
>> JOHNSCIEBHISTB
>>
>> and this is the XML output I'd like:
>>
>> <StudentGrades>
>> <StudentGrade>
>> <Name>JANE</Name>
>> <SubjectGrade>
>> <Subject>ENGL</Subject>
>> <Grade>C</Grade>
>> </SubjectGrade>
>> <SubjectGrade>
>> <Subject>MATH</Subject>
>> <Grade>A</Grade>
>> </SubjectGrade>
>> </StudentGrade>
>> <StudentGrade>
>> <Name>JOHN</Name>
>> <SubjectGrade>
>> <Subject>SCIE</Subject>
>> <Grade>B</Grade>
>> </SubjectGrade>
>> <SubjectGrade>
>> <Subject>HIST</Subject>
>> <Grade>B</Grade>
>> </SubjectGrade>
>> </StudentGrade>
>> </StudentGrades>
>>
>> Thanks,
>>
>> -Ken
>>
>>
****************************************************************************
>> This email may contain confidential material.
>> If you were not an intended recipient,
>> Please notify the sender and delete all copies.
>> We may monitor email to and from our network.
>>
****************************************************************************
>>
>>
>> -------------------------------------------------------
>> This SF.net email is sponsored by: Splunk Inc. Do you grep through log
>> files
>> for problems? Stop! Download the new AJAX search engine that makes
>> searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
>> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
>> _______________________________________________
>> Servingxml-help mailing list
>> Ser...@li...
>> https://lists.sourceforge.net/lists/listinfo/servingxml-help
>>
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log
> files
> for problems? Stop! Download the new AJAX search engine that makes
> searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> Servingxml-help mailing list
> Ser...@li...
> https://lists.sourceforge.net/lists/listinfo/servingxml-help
>
****************************************************************************
This email may contain confidential material.
If you were not an intended recipient,
Please notify the sender and delete all copies.
We may monitor email to and from our network.
****************************************************************************
|