Thread: [Practicalxml-commits] SF.net SVN: practicalxml:[142] branches/dev-1.1/src/main/java/net/sf/ practi
Brought to you by:
kdgregory
From: Auto-Generated S. C. M. <pra...@li...> - 2009-09-22 15:05:43
|
Revision: 142 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=142&view=rev Author: kdgregory Date: 2009-09-22 15:05:25 +0000 (Tue, 22 Sep 2009) Log Message: ----------- add conversion options, package docs Added Paths: ----------- branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Json2XmlOptions.java branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonOptions.java branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/package.html Added: branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Json2XmlOptions.java =================================================================== --- branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Json2XmlOptions.java (rev 0) +++ branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Json2XmlOptions.java 2009-09-22 15:05:25 UTC (rev 142) @@ -0,0 +1,31 @@ +// Copyright 2008-2009 severally by the contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package net.sf.practicalxml.converter.json; + + +/** + * Options to control conversion from JSON strings to XML documents. + */ +public enum Json2XmlOptions +{ + /** + * Convert JSON arrays to repeated XML elements with the same name. + * Default behavior is to create a parent-children construct, in which + * the parent has the given element name, while each child is named + * "data" (this approach can be subsequently passed to the XML->Java + * converter). + */ + ARRAYS_AS_REPEATED_ELEMENTS +} Added: branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonOptions.java =================================================================== --- branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonOptions.java (rev 0) +++ branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonOptions.java 2009-09-22 15:05:25 UTC (rev 142) @@ -0,0 +1,29 @@ +// Copyright 2008-2009 severally by the contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package net.sf.practicalxml.converter.json; + + +/** + * Options to control conversion from XML documents to JSON strings + */ +public enum Xml2JsonOptions +{ + /** + * Examines the XML element for an <code>xsi:type</code> attribute; if + * present, will only quote-delimit character data (<code>xsd:string</code>, + * <code>xsd:char</code>, and the like). + */ + USE_XSI_TYPE +} Added: branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/package.html =================================================================== --- branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/package.html (rev 0) +++ branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/package.html 2009-09-22 15:05:25 UTC (rev 142) @@ -0,0 +1,38 @@ +<html> +<body> + +This package contains classes to convert JSON (JavaScript Object Notation) +strings (as defined <a href="http://www.json.org/">json.org</a> ) to and +from an XML DOM. Although both XML and JSON are textual representations of +hierarchical data, there are some peculiarities in the conversion: + +<dl> +<dt> Container Element +<dd> Although elements within a JSON object are named, the object itself is + not. XML requires a named root element, so the JSON->XML conversion + creates a root element named "data", and the XML->JSON conversion ignores + the passed root element. +<dt> Document Order +<dd> In XML, document order is important and may be validated; in JSON, the + order of elements within an object is not important. To support arrays + (qv), the XML->JSON conversion intentionally breaks document order. And + as JSON has no intrinsic order, you'll need to explicitly re-arrange the + result of a JSON->XML conversion prior to any validation. +<dt> Non-String Data +<dd> JSON supports numbers and boolean literals in addition to quote-delimited + strings. The JSON->XML conversion will handle these values transparently. + The default XML->JSON conversion writes all content as quote-delimited + strings, but there is a conversion option to recognize a limited set of + non-string elements based on the <code>xsi:type</code> attribute. +<dt> Arrays +<dd> XML does not have a defined array construct, but may repeat elements; JSON + has a defined array construct, and repeated elements will overwrite the + former definition. To avoid this problem, the XML->JSON conversion will + identify all repeated elements and create an array construct. The default + JSON->XML conversion creates a parent-children construct (which is more + palatable to subsequent XML->Java conversion), but a conversion option + allows conversion to a repeated element. +</dl> + +</body> +</html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2009-09-22 15:27:17
|
Revision: 143 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=143&view=rev Author: kdgregory Date: 2009-09-22 15:27:06 +0000 (Tue, 22 Sep 2009) Log Message: ----------- add conversion options to ctors Modified Paths: -------------- branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Json2XmlConverter.java branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonConverter.java Modified: branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Json2XmlConverter.java =================================================================== --- branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Json2XmlConverter.java 2009-09-22 15:05:25 UTC (rev 142) +++ branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Json2XmlConverter.java 2009-09-22 15:27:06 UTC (rev 143) @@ -14,6 +14,8 @@ package net.sf.practicalxml.converter.json; +import java.util.EnumSet; + import org.w3c.dom.Element; import net.sf.practicalxml.DomUtil; @@ -33,17 +35,24 @@ */ public class Json2XmlConverter { + private EnumSet<Json2XmlOptions> _options = EnumSet.noneOf(Json2XmlOptions.class); private String _src; // we pull substrings from the base string private int _curPos; // position of current token (start of substring) private int _nextPos; // position of next token (end of substring) - public Json2XmlConverter(String src) + public Json2XmlConverter(String src, Json2XmlOptions... options) { _src = src; + for (Json2XmlOptions option : options) + _options.add(option); } +//---------------------------------------------------------------------------- +// Public Methods +//---------------------------------------------------------------------------- + /** * Creates a new XML <code>Document</code> from the passed JSON string * (which must contain an object definition and nothing else). The root Modified: branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonConverter.java =================================================================== --- branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonConverter.java 2009-09-22 15:05:25 UTC (rev 142) +++ branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonConverter.java 2009-09-22 15:27:06 UTC (rev 143) @@ -14,6 +14,7 @@ package net.sf.practicalxml.converter.json; +import java.util.EnumSet; import java.util.Iterator; import java.util.List; @@ -27,6 +28,20 @@ */ public class Xml2JsonConverter { + private EnumSet<Json2XmlOptions> _options = EnumSet.noneOf(Json2XmlOptions.class); + + + public Xml2JsonConverter(Json2XmlOptions... options) + { + for (Json2XmlOptions option : options) + _options.add(option); + } + + +//---------------------------------------------------------------------------- +// Public Methods +//---------------------------------------------------------------------------- + /** * Appends the contents of the specified element to an existing buffer. * Returns the buffer as a convenience. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2009-09-22 20:01:35
|
Revision: 147 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=147&view=rev Author: kdgregory Date: 2009-09-22 20:01:27 +0000 (Tue, 22 Sep 2009) Log Message: ----------- remove Xml2JsonOptions.USE_XSI_TYPE Modified Paths: -------------- branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonOptions.java branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/package.html Modified: branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonOptions.java =================================================================== --- branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonOptions.java 2009-09-22 19:21:25 UTC (rev 146) +++ branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonOptions.java 2009-09-22 20:01:27 UTC (rev 147) @@ -20,10 +20,5 @@ */ public enum Xml2JsonOptions { - /** - * Examines the XML element for an <code>xsi:type</code> attribute; if - * present, will only quote-delimit character data (<code>xsd:string</code>, - * <code>xsd:char</code>, and the like). - */ - USE_XSI_TYPE + // nothing here right now } Modified: branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/package.html =================================================================== --- branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/package.html 2009-09-22 19:21:25 UTC (rev 146) +++ branches/dev-1.1/src/main/java/net/sf/practicalxml/converter/json/package.html 2009-09-22 20:01:27 UTC (rev 147) @@ -22,8 +22,7 @@ <dd> JSON supports numbers and boolean literals in addition to quote-delimited strings. The JSON to XML conversion will handle these values transparently. The default XML to JSON conversion writes all content as quote-delimited - strings, but there is a conversion option to recognize a limited set of - non-string elements based on the <code>xsi:type</code> attribute. + strings (although this may change). <dt> Arrays, XML to JSON <dd> XML does not have a defined array construct, but may repeat elements; JSON has a defined array construct, and repeated elements will overwrite the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |