Thank you, that was very helpful, hopefully it will help someone else too. After reading your response it looks like it was a no brainer. The schema I am working on is very large and I had not worked with dfdl before this one, so it was kind of trial and error for me. maxOccurs unbounded did not work ([error] Parse Error: No forward progress.), but I set it to 9 and then it was fine. I had to adjust min/max occurs for each element too.
As per Mike's response, that is a good point. As I was getting stuck, I considered just parsing the edi segments into a flat structure xml file and restructuring it with XSLT. I just thought my requirement shouldn't be that complicated as to require one additional transformation step. On Tue, Dec 14, 2021 at 2:26 PM Steve Lawrence <slawre...@apache.org> wrote: > That's a very good point. So far, the physical structure has pretty much > matched that desired structure, just with some extra complex types > thrown in and minor tweaks needed. Though it wouldn't surprise me if we > run into limitations getting this EDI XML to look exactly like you want. > At which point we'll have to resort to the input/outputValueCalc > approach, which can get messy fast, or the need for XSLT or some other > transformation language. > > > On 12/14/21 8:07 AM, Mike Beckerle wrote: > > In general, the shape of the XML you get from dfdl is constrained by the > format > > needs. > > > > You dont generally get to decide what you want the XML to look like and > then use > > dfdl to populate that. > > > > In that situation you really have two problems: > > 1) describe the structure of the physical data (as is) > > 2) describe how to map it to the structure you want instead. > > > > Dfdl is only about problem (1) above, and we have consciously tried not > to turn > > it into a mapping language as for (2). > > > > Now, all that said, using hidden groups, dfdl:inputValueCalc and > > dfdl:outputValueCalc, you really can get it to do pretty complex > mappings. > > > > Witness this example > > https://github.com/OpenDFDL/examples/tree/master/pairsTransform > > <https://github.com/OpenDFDL/examples/tree/master/pairsTransform> which > converts > > data that is physically stored as a pair of lists into XML that is a > list of > > pairs, effectively this is transposing a matrix. > > > > Another example is parsing IPv4 packets. If you want the IP addresses to > show up > > in the XML as <src>1.2.3.4</src> then you have to create quite complex > dfdl > > which is too complex to be considered declarative description. I > consider this > > as a good example of what NOT to do in dfdl. See > > > https://github.com/DFDLSchemas/ethernetIP/blob/master/src/main/resources/com/owlcyberdefense/dfdl/xsd/ipAddress.dfdl.xsd > > < > https://github.com/DFDLSchemas/ethernetIP/blob/master/src/main/resources/com/owlcyberdefense/dfdl/xsd/ipAddress.dfdl.xsd > > > > starting at line 56 to see what I mean. It is definitely possible to get > dfdl to > > do this. It is just not recommended as a good practice. > > > > So philosophically, it can be helpful to think of dfdl as only being > about > > describing the original data format. But .... one can do more > transforming than > > this if you must. > > > > > > > > > > On Wed, Dec 1, 2021, 9:37 AM Nestor Fernandez < > nestor.fernan...@chakray.co.uk > > <mailto:nestor.fernan...@chakray.co.uk>> wrote: > > > > Hi team, > > > > We have a requirement that some of the resulting XML elements after > parsing > > an EDIFACT file should be nested or wrapped by some grouping > element. > > > > Given an edi file with a flat structure like this: > > > > segment1 > > segment2 > > segment3 > > segment4 > > > > our final goal would be to get an xml file with a more complex > structure > > such as this: > > > > <xml> > > <segment1/> > > <segment-wrapper> > > <segment-wrapper> > > <segment2/> > > <segment3/> > > </segment-wrapper> > > <segment4/> > > </segment-wrapper> > > </xml> > > > > I know we could just use XSLT, but is it even possible just with > Daffodil > > libraries? I am new to DFDL, and thought this would be very simple, > but all > > things I tried have failed (either XSD is not valid, or I get > daffodil > > runtime errors). I am using apache-daffodil-3.1.0 command line > interface. > > > > > > I put together a more practical example: > > > > INPUT EDI file: > > > > HDR+1+0+59.97+64.92+4.95+Wed Nov 15 13?:45?:28 EST > > 2006'CUS+user1+Harry:Fletcher+SD'ORD+1+1+364+The 40-Year-Old > > Virgin+29.98'ORD+2+1+299+Pulp Fiction+29.99' > > > > > > DFDL XSD Schema file: > > > > <?xml version="1.0" encoding="UTF-8" standalone="no"?> > > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema > > <http://www.w3.org/2001/XMLSchema>" > > xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/ > > <http://www.ogf.org/dfdl/dfdl-1.0/>" > > xmlns:ibmEdiFmt="http://www.ibm.com/dfdl/EDI/Format > > <http://www.ibm.com/dfdl/EDI/Format>"> > > <xsd:import namespace="http://www.ibm.com/dfdl/EDI/Format > > <http://www.ibm.com/dfdl/EDI/Format>" > schemaLocation="IBM_EDI_Format.xsd"/> > > <xsd:annotation> > > <xsd:appinfo source="http://www.ogf.org/dfdl/ > > <http://www.ogf.org/dfdl/>"> > > <dfdl:format ref="ibmEdiFmt:EDIFormat"/> > > </xsd:appinfo> > > </xsd:annotation> > > <xsd:element name="Order"> > > <xsd:complexType> > > <xsd:sequence dfdl:initiatedContent="yes"> > > <xsd:element dfdl:initiator="HDR" > > dfdl:ref="ibmEdiFmt:EDISegmentFormat" name="header" type="HDR"/> > > <xsd:element dfdl:initiator="CUS" > > dfdl:ref="ibmEdiFmt:EDISegmentFormat" name="customer-details" > type="CUS"/> > > <xsd:element dfdl:initiator="ORD" > > dfdl:ref="ibmEdiFmt:EDISegmentFormat" name="order-item" > > maxOccurs="unbounded" type="ORD"/> > > </xsd:sequence> > > </xsd:complexType> > > </xsd:element> > > <xsd:complexType name="HDR"> > > <xsd:sequence > dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat"> > > <xsd:element name="order-id" type="xsd:string"/> > > <xsd:element name="status-code" type="xsd:string"/> > > <xsd:element name="net-amount" type="xsd:string"/> > > <xsd:element name="total-amount" type="xsd:string"/> > > <xsd:element name="tax" type="xsd:string"/> > > <xsd:element name="date" type="xsd:string"/> > > </xsd:sequence> > > </xsd:complexType> > > <xsd:complexType name="CUS"> > > <xsd:sequence > dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat"> > > <xsd:element name="username" type="xsd:string"/> > > <xsd:element name="name"> > > <xsd:complexType> > > <xsd:sequence > > dfdl:ref="ibmEdiFmt:EDICompositeSequenceFormat"> > > <xsd:element name="firstname" > type="xsd:string"/> > > <xsd:element name="lastname" > type="xsd:string"/> > > </xsd:sequence> > > </xsd:complexType> > > </xsd:element> > > <xsd:element name="state" type="xsd:string"/> > > </xsd:sequence> > > </xsd:complexType> > > <xsd:complexType name="ORD"> > > <xsd:sequence > dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat"> > > <xsd:element name="position" type="xsd:string"/> > > <xsd:element name="quantity" type="xsd:string"/> > > <xsd:element name="product-id" type="xsd:string"/> > > <xsd:element name="title" type="xsd:string"/> > > <xsd:element name="price" type="xsd:string"/> > > </xsd:sequence> > > </xsd:complexType> > > </xsd:schema> > > > > > > OUTPUT: > > > > <Order> > > <header> > > <order-id>1</order-id> > > <status-code>0</status-code> > > <net-amount>59.97</net-amount> > > <total-amount>64.92</total-amount> > > <tax>4.95</tax> > > <date>Wed Nov 15 13:45:28 EST 2006</date> > > </header> > > <customer-details> > > <username>user1</username> > > <name> > > <firstname>Harry</firstname> > > <lastname>Fletcher</lastname> > > </name> > > <state>SD</state> > > </customer-details> > > <order-item> > > <position>1</position> > > <quantity>1</quantity> > > <product-id>364</product-id> > > <title>The 40-Year-Old Virgin</title> > > <price>29.98</price> > > </order-item> > > <order-item> > > <position>2</position> > > <quantity>1</quantity> > > <product-id>299</product-id> > > <title>Pulp Fiction</title> > > <price>29.99</price> > > </order-item> > > </Order> > > > > > > Let's say we want to nest XML elements (originally EDI segments), > header and > > custom-details, and get something similar to this: > > > > EXAMPLE OF DESIRED OUTPUT: > > > > <Order> > > <order-info> > > <header> > > <order-id>1</order-id> > > <status-code>0</status-code> > > <net-amount>59.97</net-amount> > > <total-amount>64.92</total-amount> > > <tax>4.95</tax> > > <date>Wed Nov 15 13:45:28 EST 2006</date> > > </header> > > <customer-details> > > <username>user1</username> > > <name> > > <firstname>Harry</firstname> > > <lastname>Fletcher</lastname> > > </name> > > <state>SD</state> > > </customer-details> > > </order-info> > > <order-item> > > <position>1</position> > > <quantity>1</quantity> > > <product-id>364</product-id> > > <title>The 40-Year-Old Virgin</title> > > <price>29.98</price> > > </order-item> > > <order-item> > > <position>2</position> > > <quantity>1</quantity> > > <product-id>299</product-id> > > <title>Pulp Fiction</title> > > <price>29.99</price> > > </order-item> > > </Order> > > > > > > Any ideas would be appreciated. > > > > Thanks and regards > > > >