Skip to content

Commit 366e0cf

Browse files
committed
docs: add XPath 3.1 json-to-xml compliance and xpath_format parameter documentation
1 parent 2969218 commit 366e0cf

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

README.rst

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ json2xml supports the following features:
3636
* Conversion from a `json` string to XML
3737
* Conversion from a `json` file to XML
3838
* Conversion from an API that emits `json` data to XML
39+
* Compliant with the `json-to-xml` function specification from `XPath 3.1 <https://www.w3.org/TR/xpath-functions-31/#func-json-to-xml>`_
3940

4041
Usage
4142
^^^^^
@@ -167,25 +168,42 @@ You can also specify if the output XML needs to have type specified or not. Here
167168

168169
.. code-block:: python
169170
170-
from json2xml import json2xml
171-
from json2xml.utils import readfromurl, readfromstring, readfromjson
171+
from json2xml import json2xml
172+
from json2xml.utils import readfromurl, readfromstring, readfromjson
172173
173-
data = readfromstring(
174-
'{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
175-
)
176-
print(json2xml.Json2xml(data, wrapper="all", pretty=True, attr_type=False).to_xml())
174+
data = readfromstring(
175+
'{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
176+
)
177+
print(json2xml.Json2xml(data, wrapper="all", pretty=True, attr_type=False).to_xml())
177178
178179
179180
Outputs this:
180181

181182
.. code-block:: xml
182183
183-
<?xml version="1.0" ?>
184-
<all>
185-
<login>mojombo</login>
186-
<id>1</id>
187-
<avatar_url>https://avatars0.githubusercontent.com/u/1?v=4</avatar_url>
188-
</all>
184+
<?xml version="1.0" ?>
185+
<all>
186+
<login>mojombo</login>
187+
<id>1</id>
188+
<avatar_url>https://avatars0.githubusercontent.com/u/1?v=4</avatar_url>
189+
</all>
190+
191+
192+
XPath 3.1 Compliance Options
193+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
194+
195+
The library supports the optional `xpath_format` parameter which makes the output compliant with the `json-to-xml` function specification from `XPath 3.1 <https://www.w3.org/TR/xpath-functions-31/#func-json-to-xml>`_. When enabled, the XML output follows the standardized format defined by the W3C specification.
196+
197+
.. code-block:: python
198+
199+
from json2xml import json2xml
200+
from json2xml.utils import readfromstring
201+
202+
data = readfromstring(
203+
'{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
204+
)
205+
# Use xpath_format=True for XPath 3.1 compliant output
206+
print(json2xml.Json2xml(data, xpath_format=True).to_xml())
189207
190208
191209
The methods are simple and easy to use and there are also checks inside of code to exit cleanly

0 commit comments

Comments
 (0)