You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "Johannes Peter (JIRA)" <ji...@apache.org> on 2018/04/24 21:56:00 UTC

[jira] [Commented] (NIFI-5113) Add XML record writer

    [ https://issues.apache.org/jira/browse/NIFI-5113?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16451277#comment-16451277 ] 

Johannes Peter commented on NIFI-5113:
--------------------------------------

[~markap14]

Hi Mark,

I am wondering how I can solve the following issue:
Assuming we have the following record:

{code}
MapRecord[{ID=1, NAME=Cleve Butler, AGE=42}]
{code}

Defining a schema for this is straightforward, as long as all keys shall be tags and all values shall be characters:

Schema:
{code}
{
  "namespace": "nifi",
  "name": "test",
  "type": "record",
  "fields": [
    { "name": "ID", "type": "string" },
    { "name": "NAME", "type": "string" },
    { "name": "AGE", "type": "int" },
    { "name": "COUNTRY", "type": "string" }
  ]
}
{code}

Result:
{code}
<PERSON>
  <ID>1</ID>
  <NAME>Cleve Butler</NAME>
  <AGE>42</AGE>
</PERSON>
{code}

However, I am wondering, how the schema can be defined to write XML with ID as attribute:

{code}
<PERSON ID="1">
  <NAME>Cleve Butler</NAME>
  <AGE>42</AGE>
</PERSON>
{code}

One way could be to instruct users to define a prefix for attributes via a property. Let's assume, the value of the property is "ATTR_".

The schema then has to be defined like this:
Schema:
{code}
{
  "namespace": "nifi",
  "name": "test",
  "type": "record",
  "fields": [
    { "name": "ATTR_ID", "type": "string" },
    { "name": "NAME", "type": "string" },
    { "name": "AGE", "type": "int" },
    { "name": "COUNTRY", "type": "string" }
  ]
}
{code}

When WriteXMLResult is created, the schema is checked for fields starting with "ATTR_". Matching fields are replaced by fields without the prefix. The reference to these fields is put into a list. When the above record is written to XML, the writer can check for each field, whether its reference is contained in the list. If that is the case, the field is written to the XML as attribute.

This is the best workaround I have identified so far. Do you have any other ideas? Are there already any plans to enhance records / schemas by metadata / attributes?


> Add XML record writer
> ---------------------
>
>                 Key: NIFI-5113
>                 URL: https://issues.apache.org/jira/browse/NIFI-5113
>             Project: Apache NiFi
>          Issue Type: New Feature
>            Reporter: Johannes Peter
>            Assignee: Johannes Peter
>            Priority: Major
>
> Corresponding writer for the XML record reader



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)