From c84ec0361fc4c877c698378b28ff9e8b502793b0 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 3 Feb 2020 22:25:30 -0800 Subject: [PATCH] xml example update --- README.md | 3 +- docgen.sh | 1 + docs/parsers/xml.md | 99 +++++++++++++++++++++++++++++++++++++++++++++ jc/parsers/xml.py | 5 ++- 4 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 docs/parsers/xml.md diff --git a/README.md b/README.md index 807eb84e..5d6e2837 100755 --- a/README.md +++ b/README.md @@ -1679,7 +1679,8 @@ $ cat cd_catalog.xml | jc --xml -p "PRICE": "9.90", "YEAR": "1988" }, -... + ... +} ``` ### YAML ``` diff --git a/docgen.sh b/docgen.sh index f62d5f66..4d9becb5 100755 --- a/docgen.sh +++ b/docgen.sh @@ -37,4 +37,5 @@ pydocmd simple jc.parsers.systemctl_luf+ > ../docs/parsers/systemctl_luf.md pydocmd simple jc.parsers.uname+ > ../docs/parsers/uname.md pydocmd simple jc.parsers.uptime+ > ../docs/parsers/uptime.md pydocmd simple jc.parsers.w+ > ../docs/parsers/w.md +pydocmd simple jc.parsers.xml+ > ../docs/parsers/xml.md pydocmd simple jc.parsers.yaml+ > ../docs/parsers/yaml.md diff --git a/docs/parsers/xml.md b/docs/parsers/xml.md new file mode 100644 index 00000000..c781ee33 --- /dev/null +++ b/docs/parsers/xml.md @@ -0,0 +1,99 @@ +# jc.parsers.xml +jc - JSON CLI output utility XML Parser + +Usage: + + specify --xml as the first argument if the piped input is coming from a XML file + +Compatibility: + + 'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd' + +Examples: + + $ cat cd_catalog.xml + + + + Empire Burlesque + Bob Dylan + USA + Columbia + 10.90 + 1985 + + + Hide your heart + Bonnie Tyler + UK + CBS Records + 9.90 + 1988 + + ... + + $ cat cd_catalog.xml | jc --xml -p + { + "CATALOG": { + "CD": [ + { + "TITLE": "Empire Burlesque", + "ARTIST": "Bob Dylan", + "COUNTRY": "USA", + "COMPANY": "Columbia", + "PRICE": "10.90", + "YEAR": "1985" + }, + { + "TITLE": "Hide your heart", + "ARTIST": "Bonnie Tyler", + "COUNTRY": "UK", + "COMPANY": "CBS Records", + "PRICE": "9.90", + "YEAR": "1988" + }, + ... + } + +## info +```python +info(self, /, *args, **kwargs) +``` + +## process +```python +process(proc_data) +``` + +Final processing to conform to the schema. + +Parameters: + + proc_data: (dictionary) raw structured data to process + +Returns: + + Dictionary representing an XML document: + + { + XML Document converted to a Dictionary + See https://github.com/martinblech/xmltodict for details + } + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main text parsing function + +Parameters: + + data: (string) text data to parse + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + +Returns: + + Dictionary. Raw or processed structured data. + diff --git a/jc/parsers/xml.py b/jc/parsers/xml.py index 5206fbc8..6f12a2ce 100644 --- a/jc/parsers/xml.py +++ b/jc/parsers/xml.py @@ -10,7 +10,7 @@ Compatibility: Examples: - $ cat cd_catalog.xml + $ cat cd_catalog.xml @@ -51,7 +51,8 @@ Examples: "PRICE": "9.90", "YEAR": "1988" }, - ... + ... + } """ import jc.utils import xmltodict