You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@daffodil.apache.org by "Costello, Roger L." <co...@mitre.org> on 2018/10/03 18:02:28 UTC
How to declare an element whose name is the value of another element?
Hello DFDL community,
My input file first has column headings such as "name" and "line". After the column headings come a series of records. The first field in each record should be labeled by the first column heading, the second field by the second column header, and so forth. For example, if the column header has this:
<columns>
<column>
<name>name</name>
</column>
<column>
<name>line</name>
</column>
</columns>
Then a record would look like this:
<record>
<name>Van Dorn Street</name>
<line>blue</line>
</record>
How to dynamically generate an element name? I imagine something along these lines:
<xs:element name="record" ...>
<xs:complexType>
<xs:sequence>
<xs:element name="{get the value of ../../columns/column[1]/name}" .../>
<xs:element name="{get the value of ../../columns/column[2]/name}" .../>
</xs:sequence>
</xs:complexType>
</xs:element>
Is it possible in DFDL to declare an element with a name that is the value of a previous field?
/Roger
Re: How to declare an element whose name is the value of another
element?
Posted by Mike Beckerle <mb...@tresys.com>.
Short answer, no.
We ran into this same issue with IPFIX I think. It has descriptive stuff at the start, then data according to that description. Actually in IPFIX I think you can have a bunch of alternating blocks of description and data
You have to generate a DFDL schema from the descriptive stuff, then compile and use that to parse.
It's an artifact of XML Schema that we cannot have a schema for
<foo>bar</foo>
unless "foo" is a constant found in the XML Schema as the value of the name attribute of some element declaration.
Is there an easy XSLT that would take all occurrences of:
<item>
<name>foo</name>
<value>bar</value>
</item>
and create
<foo>bar</foo>
???
I would hope that's an easy XSLT, but I haven't given it much thought.
________________________________
From: Costello, Roger L. <co...@mitre.org>
Sent: Wednesday, October 3, 2018 2:02:28 PM
To: users@daffodil.apache.org
Subject: How to declare an element whose name is the value of another element?
Hello DFDL community,
My input file first has column headings such as "name" and "line". After the column headings come a series of records. The first field in each record should be labeled by the first column heading, the second field by the second column header, and so forth. For example, if the column header has this:
<columns>
<column>
<name>name</name>
</column>
<column>
<name>line</name>
</column>
</columns>
Then a record would look like this:
<record>
<name>Van Dorn Street</name>
<line>blue</line>
</record>
How to dynamically generate an element name? I imagine something along these lines:
<xs:element name="record" ...>
<xs:complexType>
<xs:sequence>
<xs:element name="{get the value of ../../columns/column[1]/name}" .../>
<xs:element name="{get the value of ../../columns/column[2]/name}" .../>
</xs:sequence>
</xs:complexType>
</xs:element>
Is it possible in DFDL to declare an element with a name that is the value of a previous field?
/Roger