Skip to content

@xmlns in JSON not showing up when converting to XML #9

@mwooten

Description

@mwooten

It looks like the changes made to the processAttributesAndNamespaces(Node n, JSONObject object) method in the MappedNamespaceConvention.java source back in the 2.0 release, no longer processes no prefix attributes correctly. In the 1.0 release, the following JSON:

{ "toy": { "@xmlns": "http://examples.com" }}

Produced the following XML, when converted:

<toy xmlns="http://examples.com"/>

It no longer does that, starting with the 2.0 release. One possible fix is to add:

if (o instanceof String) {
    String uri = o.toString();
    QName name = new QName( XMLConstants.DEFAULT_NS_PREFIX, k );
    n.setAttribute(name, uri); 
}

after the following if statement:

if ( o instanceof JSONObject ) {
    JSONObject jo = (JSONObject) o;
     for (Iterator<?> pitr = jo.keys(); pitr.hasNext();) {
         // set namespace if one is specified on this attribute.
         String prefix = (String) pitr.next();
         String uri = jo.getString( prefix );
         //                            if ( prefix.equals( "$" ) ) {
         //                                prefix = "";
         //                            }

        n.setNamespace( prefix, uri );
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions