Skip to content

Commit

Permalink
Merge pull request #219 from ajgarlag/xml-element-notation-consistency
Browse files Browse the repository at this point in the history
@xmlelement notation consistency
  • Loading branch information
schmittjoh committed Jan 22, 2014
2 parents 9ef1b5c + 1523a7e commit 67cf0f4
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 37 deletions.
3 changes: 1 addition & 2 deletions doc/reference/xml_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ XML Reference
xml-key-value-pairs="true"
xml-attribute-map="true"
max-depth="2"
xml-namespace="http://www.w3.org/2005/Atom"
>
<!-- You can also specify the type as element which is necessary if
your type contains "<" or ">" characters. -->
<type><![CDATA[]]></type>
<xml-list inline="true" entry-name="foobar" />
<xml-map inline="true" key-attribute-name="foo" entry-name="bar" />
<xml-element cdata="false" />
<xml-element cdata="false" namespace="http://www.w3.org/2005/Atom"/>
</property>
<callback-method name="foo" type="pre-serialize" />
<callback-method name="bar" type="post-serialize" />
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/yml_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ YAML Reference
xml_attribute_map: true
xml_element:
cdata: false
namespace: http://www.w3.org/2005/Atom
max_depth: 2
xml_namespace: http://www.w3.org/2005/Atom

handler_callbacks:
serialization:
Expand Down
8 changes: 4 additions & 4 deletions src/JMS/Serializer/Metadata/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ protected function loadMetadataFromFile(\ReflectionClass $class, $path)
if (null !== $groups = $pElem->attributes()->groups) {
$pMetadata->groups = preg_split('/\s*,\s*/', (string) $groups);
}

if (null !== $xmlNamespace = $pElem->attributes()->{'xml-namespace'}) {
$pMetadata->xmlNamespace = (string) $xmlNamespace;
}

if (isset($pElem->{'xml-list'})) {
$pMetadata->xmlCollection = true;
Expand Down Expand Up @@ -194,6 +190,10 @@ protected function loadMetadataFromFile(\ReflectionClass $class, $path)
if (isset($colConfig->attributes()->cdata)) {
$pMetadata->xmlElementCData = 'true' === (string) $colConfig->attributes()->cdata;
}

if (isset($colConfig->attributes()->namespace)) {
$pMetadata->xmlNamespace = (string) $colConfig->attributes()->namespace;
}
}

if (isset($pElem->attributes()->{'xml-attribute'})) {
Expand Down
8 changes: 4 additions & 4 deletions src/JMS/Serializer/Metadata/Driver/YamlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ protected function loadMetadataFromFile(\ReflectionClass $class, $file)
$pMetadata->groups = $pConfig['groups'];
}

if (isset($pConfig['xml_namespace'])) {
$pMetadata->xmlNamespace = (string) $pConfig['xml_namespace'];
}

if (isset($pConfig['xml_list'])) {
$pMetadata->xmlCollection = true;

Expand Down Expand Up @@ -179,6 +175,10 @@ protected function loadMetadataFromFile(\ReflectionClass $class, $file)
if (isset($colConfig['cdata'])) {
$pMetadata->xmlElementCData = (Boolean) $colConfig['cdata'];
}

if (isset($colConfig['namespace'])) {
$pMetadata->xmlNamespace = (string) $colConfig['namespace'];
}
}

if (isset($pConfig['xml_attribute'])) {
Expand Down
12 changes: 9 additions & 3 deletions tests/JMS/Serializer/Tests/Metadata/Driver/xml/BlogPost.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@
<property name="id" type="string" groups="comments,post">
<xml-element cdata="false"/>
</property>
<property name="title" type="string" groups="comments,post" xml-namespace="http://purl.org/dc/elements/1.1/"/>
<property name="title" type="string" groups="comments,post">
<xml-element namespace="http://purl.org/dc/elements/1.1/"/>
</property>
<property name="createdAt" xml-attribute="true" type="DateTime"/>
<property name="published" type="boolean" serialized-name="is_published" xml-attribute="true" groups="post" />
<property name="etag" type="string" xml-attribute="true" xml-namespace="http://schemas.google.com/g/2005" groups="post" />
<property name="etag" type="string" xml-attribute="true" groups="post">
<xml-element namespace="http://schemas.google.com/g/2005"/>
</property>
<property name="comments" groups="comments">
<type><![CDATA[ArrayCollection<JMS\Serializer\Tests\Fixtures\Comment>]]></type>
<xml-list inline="true" entry-name="comment" />
</property>
<property name="author" groups="post" type="JMS\Serializer\Tests\Fixtures\Author" xml-namespace="http://www.w3.org/2005/Atom"/>
<property name="author" groups="post" type="JMS\Serializer\Tests\Fixtures\Author">
<xml-element namespace="http://www.w3.org/2005/Atom"/>
</property>
</class>
</serializer>
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
<xml-namespace uri="http://example.com/namespace"/>
<xml-namespace prefix="gd" uri="http://schemas.google.com/g/2005"/>
<xml-namespace prefix="atom" uri="http://www.w3.org/2005/Atom"/>
<property name="title" type="string" xml-namespace="http://purl.org/dc/elements/1.1/"/>
<property name="title" type="string">
<xml-element namespace="http://purl.org/dc/elements/1.1/"/>
</property>
<property name="createdAt" xml-attribute="true" type="DateTime"/>
<property name="etag" type="string" xml-attribute="true" xml-namespace="http://schemas.google.com/g/2005"/>
<property name="author" type="string" xml-namespace="http://www.w3.org/2005/Atom"/>
<property name="language" type="string" xml-attribute="true" xml-namespace="http://purl.org/dc/elements/1.1/"/>
<property name="etag" type="string" xml-attribute="true">
<xml-element namespace="http://schemas.google.com/g/2005"/>
</property>
<property name="author" type="string">
<xml-element namespace="http://www.w3.org/2005/Atom"/>
</property>
<property name="language" type="string" xml-attribute="true">
<xml-element namespace="http://purl.org/dc/elements/1.1/"/>
</property>
</class>
</serializer>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
<xml-namespace prefix="foo" uri="http://foo.example.org"/>
<xml-namespace prefix="old_foo" uri="http://old.foo.example.org"/>
<xml-namespace prefix="new_foo" uri="http://new.foo.example.org"/>
<property name="foo" type="string" xml-attribute="true" xml-namespace="http://old.foo.example.org"/>
<property name="bar" type="string" xml-namespace="http://foo.example.org"/>
<property name="moo" type="string" xml-namespace="http://new.foo.example.org"/>
<property name="foo" type="string" xml-attribute="true">
<xml-element namespace="http://old.foo.example.org"/>
</property>
<property name="bar" type="string">
<xml-element namespace="http://foo.example.org"/>
</property>
<property name="moo" type="string">
<xml-element namespace="http://new.foo.example.org"/>
</property>
</class>
</serializer>
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
<class name="JMS\Serializer\Tests\Fixtures\SimpleSubClassObject">
<xml-namespace prefix="foo" uri="http://better.foo.example.org"/>
<xml-namespace prefix="old_foo" uri="http://foo.example.org"/>
<property name="moo" type="string" xml-namespace="http://better.foo.example.org"/>
<property name="baz" type="string" xml-namespace="http://foo.example.org"/>
<property name="qux" type="string" xml-namespace="http://new.foo.example.org"/>
<property name="moo" type="string">
<xml-element namespace="http://better.foo.example.org"/>
</property>
<property name="baz" type="string">
<xml-element namespace="http://foo.example.org"/>
</property>
<property name="qux" type="string">
<xml-element namespace="http://new.foo.example.org"/>
</property>
</class>
</serializer>
9 changes: 6 additions & 3 deletions tests/JMS/Serializer/Tests/Metadata/Driver/yml/BlogPost.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ JMS\Serializer\Tests\Fixtures\BlogPost:
title:
type: string
groups: [comments, post]
xml_namespace: http://purl.org/dc/elements/1.1/
xml_element:
namespace: http://purl.org/dc/elements/1.1/
createdAt:
type: DateTime
xml_attribute: true
Expand All @@ -27,7 +28,8 @@ JMS\Serializer\Tests\Fixtures\BlogPost:
type: string
groups: [post]
xml_attribute: true
xml_namespace: http://schemas.google.com/g/2005
xml_element:
namespace: http://schemas.google.com/g/2005
comments:
type: ArrayCollection<JMS\Serializer\Tests\Fixtures\Comment>
groups: [comments]
Expand All @@ -37,4 +39,5 @@ JMS\Serializer\Tests\Fixtures\BlogPost:
author:
type: JMS\Serializer\Tests\Fixtures\Author
groups: [post]
xml_namespace: http://www.w3.org/2005/Atom
xml_element:
namespace: http://www.w3.org/2005/Atom
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ JMS\Serializer\Tests\Fixtures\ObjectWithXmlNamespaces:
properties:
title:
type: string
xml_namespace: http://purl.org/dc/elements/1.1/
xml_element:
namespace: http://purl.org/dc/elements/1.1/
createdAt:
type: DateTime
xml_attribute: true
etag:
type: string
xml_attribute: true
xml_namespace: http://schemas.google.com/g/2005
xml_element:
namespace: http://schemas.google.com/g/2005
author:
type: string
xml_namespace: http://www.w3.org/2005/Atom
xml_element:
namespace: http://www.w3.org/2005/Atom
language:
type: string
xml_attribute: true
xml_namespace: http://purl.org/dc/elements/1.1/
xml_element:
namespace: http://purl.org/dc/elements/1.1/
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ JMS\Serializer\Tests\Fixtures\SimpleClassObject:
foo:
type: string
xml_attribute: true
xml_namespace: http://old.foo.example.org
xml_element:
namespace: http://old.foo.example.org
bar:
type: string
xml_namespace: http://foo.example.org
xml_element:
namespace: http://foo.example.org
moo:
type: string
xml_namespace: http://new.foo.example.org
xml_element:
namespace: http://new.foo.example.org
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ JMS\Serializer\Tests\Fixtures\SimpleSubClassObject:
properties:
moo:
type: string
xml_namespace: http://better.foo.example.org
xml_element:
namespace: http://better.foo.example.org
baz:
type: string
xml_namespace: http://foo.example.org
xml_element:
namespace: http://foo.example.org
qux:
type: string
xml_namespace: http://new.foo.example.org
xml_element:
namespace: http://new.foo.example.org

0 comments on commit 67cf0f4

Please sign in to comment.