You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[See it here in the Playground.](https://metafacture.org/playground/?flux=inputFile%0A%7C+open-file%0A%7C+as-records%0A%7C+print%0A%3B&data=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%0A%3Crecord%3E%0A++%3Ctitle%3EGRM%3C/title%3E%0A++%3Cauthor%3ESibille+Berg%3C/author%3E%0A++%3CdatePublished%3E2019%3C/datePublished%3E%0A%3C/record%3E)
28
35
29
36
Next lets decode the file and encode it as Yaml.
30
37
@@ -33,7 +40,17 @@ Handlers a specific helpers that decode xml in a certain way, based on the metad
33
40
34
41
For now we need the `handle-generic-xml` function.
[See it here in the Playground.](https://metafacture.org/playground/?flux=inputFile%0A%7C+open-file%0A%7C+decode-xml%0A%7C+handle-generic-xml%0A%7C+encode-yaml%0A%7C+print%0A%3B&data=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%0A%3Crecord%3E%0A++%3Ctitle%3EGRM%3C/title%3E%0A++%3Cauthor%3ESibille+Berg%3C/author%3E%0A++%3CdatePublished%3E2019%3C/datePublished%3E%0A%3C/record%3E)
37
54
38
55
39
56
You see this as result:
@@ -59,41 +76,142 @@ See:
59
76
<title attribute="test">Test value</title>
60
77
```
61
78
62
-
=>
79
+
With the Flux:
80
+
81
+
```text
82
+
inputFile
83
+
| open-file
84
+
| decode-xml
85
+
| handle-generic-xml
86
+
| encode-yaml
87
+
| print
88
+
;
89
+
```
63
90
64
91
```yaml
65
92
title:
66
93
attribute: "test"
67
94
value: "Test value"
68
95
```
69
96
70
-
For our example above to get rid of the value subfields in the yaml we need to change the hirachy:
97
+
[For our example above to get rid of the value subfields in the yaml we need to change the hirachy:](https://metafacture.org/playground/?flux=inputFile%0A%7C+open-file%0A%7C+decode-xml%0A%7C+handle-generic-xml%0A%7C+fix%28transformationFile%29%0A%7C+encode-yaml%0A%7C+print%0A%3B&transformation=move_field%28%22title.value%22%2C%22@title%22%29%0Amove_field%28%22@title%22%2C%22title%22%29%0Amove_field%28%22author.value%22%2C%22@author%22%29%0Amove_field%28%22@author%22%2C%22author%22%29%0Amove_field%28%22datePublished.value%22%2C%22@datePublished%22%29%0Amove_field%28%22@datePublished%22%2C%22datePublished%22%29&data=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%0A%3Crecord%3E%0A++%3Ctitle%3EGRM%3C/title%3E%0A++%3Cauthor%3ESibille+Berg%3C/author%3E%0A++%3CdatePublished%3E2019%3C/datePublished%3E%0A%3C/record%3E)
The value subfields are also kept. Keep in mind that xml elements can have attributes and a value. But also the encoder enable simple flat xml records too.
163
+
<record>
164
+
<title>GRM</title>
165
+
<author>Sibille Berg</author>
166
+
<datePublished>2019</datePublished>
167
+
</record>
80
168
81
-
You have to add a specific option when encoding xml: `(valueTag="value")`
169
+
</records>
170
+
171
+
```
82
172
83
173
If you want to create the other elements as attributes. You have to tell MF which elements are attributes by adding a attributeMarker with the option `attributemarker` in handle generic xml.
Another important thing, when working with xml data sets is to specify the record tag. Default is the tag record. But other data sets have different tags that separate records:
See this in the Playground [here](https://metafacture.org/playground/?flux=%22http%3A//www.lido-schema.org/documents/examples/LIDO-v1.1-Example_FMobj00154983-LaPrimavera.xml%22%0A%7C+open-http%0A%7C+decode-xml%0A%7C+handle-generic-xml%28recordtagname%3D%22lido%22%2C+emitnamespace%3D%22true%22%29%0A%7C+encode-yaml%0A%7C+print%0A%3B).
108
236
109
237
When you want to add the namespace definition to the output metafacture does not know that by itself but you have to tell metafacture
110
238
the new namespace when `encoding-xml` either by a file with the option `namespacefile` or in the flux with the option `namespaces`.
111
239
112
240
See here an example for adding namespaces in the flux:
0 commit comments