XmlStarlet Synk fields - xmlstarlet

I have one really big file xml. The stucture is like this:
<channel update="i" site="merge-xmltv" site_id="" xmltv_id="Rai 1">Rai 1</channel>
<channel update="i" site="merge-xmltv" site_id="" xmltv_id="Rai 1 +2HD">Rai 1 +2HD</channel>
<channel update="i" site="merge-xmltv" site_id="" xmltv_id="Rai 1 +1HD">Rai 1 +1HD</channel>
I want synk the field "site_id" with the field "xmltv_id" I need something like this:
<channel update="i" site="merge-xmltv" site_id="Rai 1" xmltv_id="Rai 1">Rai 1</channel>
<channel update="i" site="merge-xmltv" site_id="Rai 1 +2HD" xmltv_id="Rai 1 +2HD">Rai 1 +2HD</channel>
<channel update="i" site="merge-xmltv" site_id=""Rai 1 +1HD" xmltv_id="Rai 1 +1HD">Rai 1 +1HD</channel>
I tried with the command
xml ed -u "/channel/#site_id" -x "concat(/channel/#xmltv_id)" test.xml
but i think is really wrong :(

Related

Extracting and modifying XML with deep structure from Linux command line

I would like to select and change a value in an XML file. I'm trying to use xmlstarlet for this.
I have this file
<?xml version='1.0' encoding='UTF-8'?>
<DeviceDescription xmlns="http://www.3s-software.com/schemas/DeviceDescription-1.0.xsd">
<House>
<Id>
<Number>1</Number>
</Id>
</House>
<Car>
<Id>
<Number>2</Number>
</Id>
</Car>
</DeviceDescription>
My problem is the xmlns= field which xmlstarlet is picky about. Without this field I can use
xmlstarlet sel -t -v '/Description/House/Id/Number' /tmp/x.xml
I found that I can use a default namespace like this, but that returns both Id's
xmlstarlet sel -t -m "//_:Id" -v '_:Number' /tmp/x.xml
How do I specify a full path?
To only match the House id, add it to the -m argument:
xml sel -t -m '//_:House/_:Id' -v '_:Number'
If you want to use the namespace, specify it with -N, e.g.:
xml sel -N ns="http://www.3s-software.com/schemas/DeviceDescription-1.0.xsd" \
-t -v 'ns:DeviceDescription/ns:House/ns:Id/ns:Number'
So to update the value:
xml ed -N ns="http://www.3s-software.com/schemas/DeviceDescription-1.0.xsd" \
-u 'ns:DeviceDescription/ns:House/ns:Id/ns:Number' -v 3
Output:
<?xml version="1.0" encoding="UTF-8"?>
<DeviceDescription xmlns="http://www.3s-software.com/schemas/DeviceDescription-1.0.xsd">
<House>
<Id>
<Number>3</Number>
</Id>
</House>
<Car>
<Id>
<Number>2</Number>
</Id>
</Car>
</DeviceDescription>

WSO2 : Transforming response xml

I would like to turn this xml response into something more easily readable.
<?xml version="1.0" encoding="ISO-8859-1"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
<soap:Body>
<executeResponse xmlns="urn:GCE">
<BusinessViewServiceexecuteOut xmlns="http://www.generix.fr/technicalframework/businesscomponent/applicationmodule/common" xmlns:ns2="http://www.generixgroup.com/processus/configuration/scheduler" xmlns:ns3="http://www.generix.fr/technicalframework/business/service/common">
<xmlpres><?xml version = '1.0' encoding = 'UTF-8'?> <VueTable type="View" name="Table" habctr="true" total_business_row="2" nbline="400" confNbline="400" numpage="1" nbpage="1">
<JTblView name="JTblView" type="ViewObject" maxfetchsize="999" maxfetchsizeexceeded="false">
<JTblViewRow current="true" type="ViewRow" index="1" business_row_index="1">
<Cletbl precision="6" type="VARCHAR" pk="true">
<business_data>N</business_data>
</Cletbl>
<Codtbl precision="6" type="VARCHAR" pk="true">
<business_data>001</business_data>
</Codtbl>
<Lib1 precision="30" type="VARCHAR">
<business_data>Non</business_data>
</Lib1>
<Lib2 precision="30" type="VARCHAR">
<business_data/>
</Lib2>
<Lir precision="10" type="VARCHAR">
<business_data>Non</business_data>
</Lir>
</JTblViewRow>
<JTblViewRow type="ViewRow" index="2" business_row_index="2">
<Cletbl precision="6" type="VARCHAR" pk="true">
<business_data>O</business_data>
</Cletbl>
<Codtbl precision="6" type="VARCHAR" pk="true">
<business_data>001</business_data>
</Codtbl>
<Lib1 precision="30" type="VARCHAR">
<business_data>Oui</business_data>
</Lib1>
<Lib2 precision="30" type="VARCHAR">
<business_data/>
</Lib2>
<Lir precision="10" type="VARCHAR">
<business_data>Oui</business_data>
</Lir>
</JTblViewRow>
</JTblView>
</VueTable></xmlpres>
</BusinessViewServiceexecuteOut>
</executeResponse>
</soap:Body></soap:Envelope>
At least if I could extract what's in the value of "xmlpres", the better I could do:
<table><row><code></code><libelle></libelle/></row></table>
To then turn it into a json response but I can't see ... I just get all the output or in json stream but with everything , which is not usable.
Create an out-mediation sequence with the following content and attach it to the respective API and try out the scenario. This is to extract the xmlpres content and send that as the response to the client
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="out-sequence">
<!-- extract the xmlpres content and store as OM element -->
<property name="XMLBody"
expression="$body//soap:Body//generic:xmlpres"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:gce="urn:GCE"
xmlns:generic="http://www.generix.fr/technicalframework/businesscomponent/applicationmodule/common" type="OM" />
<!-- pass the extracted property as response body -->
<enrich>
<source type="property" property="XMLBody" />
<target type="body" />
</enrich>
</sequence>
Hope this helps you to extract and send the response accordingly.

Map the next node of input XML into previous node of XML schema

I have an source and destination schema like following
Source Schema:
<Root>
<STDS>
<COD>
<NAM>
<AGE>
</STDS>
</Root>
Destination Schema::
<Root>
<Students>
<Code100>
<Name>
<Age>
<Code50>
<Name>
<Age>
</Code50>
</Code100>
</Students>
</Root>
In the source input, STDS is unbounded. Node COD can have three values 100, 200 and 50. So any STDS node having the COD value = 50, should be added to the STDS with COD value = 100 prior to the current STDS node.
I have an input like.
<Root>
<STDS>
<COD>200</COD>
<NAM>ABC</NAM>
<AGE>20</AGE>
</STDS>
<STDS>
<COD>100</COD>
<NAM>XYZ</NAM>
<AGE>21</AGE>
</STDS>
<STDS>
<COD>50</COD>
<NAM>JJJ</NAM>
<AGE>22</AGE>
</STDS>
<STDS>
<COD>200</COD>
<NAM>JKL</NAM>
<AGE>23</AGE>
</STDS>
<STDS>
<COD>100</COD>
<NAM>MMM</NAM>
<AGE>24</AGE>
</STDS>
<STDS>
<COD>50</COD>
<NAM>NNN</NAM>
<AGE>25</AGE>
</STDS>
</STDS>
<STDS>
<COD>50</COD>
<NAM>LLL</NAM>
<AGE>26</AGE>
</STDS>
</Root>
I need an output like following
<Root>
<Students>
<Code200>
<Name>ABC</Name>
<Age>20</Age>
</Code200>
<Code100>
<Name>XYZ</Name>
<Age>21</Age>
<Code50>
<Name>JJJ</Name>
<Age>22</Age>
</Code50>
</Code100>
<Name>XYZ</Name>
<Age>21</Age>
</Code100>
<Code200>
<Name>JKL</Name>
<Age>23</Age>
</Code200>
</Code100>
<Name>MMM</Name>
<Age>24</Age>
<Code50>
<Name>NNN</Name>
<Age>24</Age>
</Code50>
<Code50>
<Name>LLL</Name>
<Age>25</Age>
</Code50>
</Code100>
</Students>
</Root>
I want to achieve this in BizTalk mapper without using custom XSLT.
All you need to do is
Link <COD> to <Code50>, <Code100> etc.. through an Equal Functoid that tests for 50, 100, etc.
Depending on the composition of the Schemas, you may also have to like <STDS> to <CodeXXX> through Looping Functoids.
Just like the other questions, which you should also switch back to Functoids, this can be done with Functoids only, you just have to try some combinations.

Recover .docx file from 'SAXParseException: "No namespace defined for pic"'

I cannot open a .docx file that I stored in a USB pendrive. I get following error and LibreOffice doesn't open the document:
File format error found at
SAXParseException: "No namespace defined for pic"
SAXParseException: '[word/document.xml line 2]: Namespace prefix pic on txbx is not defined
', Stream 'word/document.xml', Line 2, Column 30767(row,col).
Is there any way to recover the file?
Decompress the .docx file. If you don't know how to do it, check it here:
https://superuser.com/a/1356829/707698
In the decompressed directory, look for the file word/document.xml and open it with a text editor. In the second line you'll see something like:
<w:document xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
mc:Ignorable="w14 wp14">
You have to include following attribute in that statement:
xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
After that you'll have something like this:
<w:document xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
mc:Ignorable="w14 wp14">
Now you just need to rebuild the .docx file from the decompressed directory. If you don't know how to do it, check it here:
https://superuser.com/a/1356829/707698

decode value in xml using shell

i am trying to decode a value from xml. please find a sample below. This will be multiple blocks. I need to find tag and decode the contents and generate the same output. i am just in the process of starting the script.
<SOAP-ENV:Body>
<log-entry serial="abcde" domain="abc">
<date>Tue Oct 17 2017</date>
<time utc="abcde">14:14:30</time>
<type>all</type>
<class>ccccc</class>
<object>Web_Token</object>
<level num="5">notice</level>
<transaction>xxxxx</transaction>
<global-transaction-id>xxxxx</global-transaction-id>
<client>X.X.X.X</client>
<message>
<base64>**encodeddata**</base64>
</message>
</log-entry>
</SOAP-ENV:Body>
i need output
<SOAP-ENV:Body>
<log-entry serial="abcde" domain="abc">
<date>Tue Oct 17 2017</date>
<time utc="abcde">14:14:30</time>
<type>all</type>
<class>ccccc</class>
<object>Web_Token</object>
<level num="5">notice</level>
<transaction>xxxxx</transaction>
<global-transaction-id>xxxxx</global-transaction-id>
<client>X.X.X.X</client>
<message>
<base64>**decodeddata**</base64>
</message>
</log-entry>
</SOAP-ENV:Body>
I am in the process of Iteration, started with decoding the value.
sed -n 's/<base64>\(.*\)<\/base64>/\1/p' log.txt | base64 --decode
thanks.
Try this :
xmllint --xpath '//message/base64/text()' file.xml 2>/dev/null |
base64 -d -

Resources