Generate yaml from xml and xml from yaml
Contents
First off we should get schema for out pom.xml. It is on the head of pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">Get it:
wget http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdSecondly, we need to install xml2yaml:
-
Debian, Ubuntu, Kali Linux, Raspbian:
apt-get install libxml-compile-perl xml2yaml help ERROR: no schema's specified
Next, there are exmaples of commands:
xml2yaml xml-file schema-file(s) >yaml-file
xml2yaml -x xml-file -s schema-files -o yaml-file
# for our cas `maven-4.0.0.xsd` was downloaded on the first step
xml2yaml -x pom.xml -s maven-4.0.0.xsd -o 1.ymlThere is a useful link
After that, let’s install yq:
sudo add-apt-repository ppa:rmescandon/yq
sudo apt update
sudo apt install yqThen, try than everything is ok:
yq -vFinally, generate xml from yaml:
This we can’t get the same xml-file.
yq --xml-attribute-prefix @ \
--xml-content-name '#text' \
--input-format yaml \
--output-format xml \
1.yml > 1.xml