Skip to content

XML read/write is not idempotent #41

Description

@wenditer

Shaper currently converts xml into yaml with errors, it doesn't able to distinguish child elements and attributes. E.g. if we have the following xml:

<rest-security>
  <default-acl value="Profile$login$restUser:read,write,execute"/>
  <default-acl2>Profile$login$restUser:read,write,execute</default-acl2>
  <default-acl3 value="test">Profile$login$restUser:read,write,execute</default-acl3>
  <default-acl4 value="test">
    <value>Profile$login$restUser:read,write,execute</value>
  </default-acl4>
</rest-security>

It will be converted to yaml:

  rest-security:
    default-acl:
      '@value': Profile$login$restUser:read,write,execute
    default-acl2: Profile$login$restUser:read,write,execute
    default-acl3:
      '@value': test
      '#text': Profile$login$restUser:read,write,execute
    default-acl4:
      '@value': test
      value: Profile$login$restUser:read,write,execute

Output xml after writing this yaml will be:

	<default-acl>
		<key name="@value">Profile$login$restUser:read,write,execute</key>
	</default-acl>
	<default-acl2>Profile$login$restUser:read,write,execute</default-acl2>
	<default-acl3>
		<key name="@value">test</key>
		<key name="#text">Profile$login$restUser:read,write,execute</key>
	</default-acl3>
	<default-acl4>
		<key name="@value">test</key>
		<value>Profile$login$restUser:read,write,execute</value>
	</default-acl4>
</rest-security>

It's drastically different. Also it ignores DTD declaration, e.g. if to put <!DOCTYPE rest-security SYSTEM "dynamosystemresource:/atg/dtds/rest/restSecurity_1.0.dtd"> it will not appear in yaml.

I'd suggest as quick fix - to change parser mapping for .xml files from XMLParser to TextParser. In this case the yaml will be:

test\xmtext.xml: |-
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE rest-security SYSTEM "dynamosystemresource:/atg/dtds/rest/restSecurity_1.0.dtd">

  <rest-security>
    <default-acl value="Profile$login$restUser:read,write,execute"/>
    <default-acl2>Profile$login$restUser:read,write,execute</default-acl2>
    <default-acl3 value="test">Profile$login$restUser:read,write,execute</default-acl3>
    <default-acl4 value="test">
      <value>Profile$login$restUser:read,write,execute</value>
    </default-acl4>
  </rest-security>

And the output xml will be identical to the initial one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions