remove ID attribute from XML in Unix - unix

I want to remove ID attribute from a XML file as below. Tries some sed command but it not yielding correct result. need help in correcting my sed command
<State>
<Resident Id="100">
<Name>Sample Name</Name>
<PhoneNumber>1234567891</PhoneNumber>
<EmailAddress>sample_name#example.com</EmailAddress>
<Address>
<StreetLine1>Street Line1</StreetLine1>
<City>City Name</City>
<StateCode>AE</StateCode>
<PostalCode>12345</PostalCode>
</Address>
</Resident>
<Resident Id="101">
<Name>Sample Name1</Name>
<PhoneNumber>1234567891</PhoneNumber>
<EmailAddress>sample_name1#example.com</EmailAddress>
<Address>
<StreetLine1>Current Address</StreetLine1>
<City>Los Angeles</City>
<StateCode>CA</StateCode>
<PostalCode>56666</PostalCode>
</Address>
</Resident>
<Resident Id="" />
</State>
Tried below sed commands but it not giving me correct result.
sed -i 's/^(ID=".*)".*/\1>/' Resident.xml
sed '/ ID.*/d' Resident.xml
Want xml like below. All id attributes removed from xml.
<State>
<Resident>
<Name>Sample Name</Name>
<PhoneNumber>1234567891</PhoneNumber>
<EmailAddress>sample_name#example.com</EmailAddress>
<Address>
<StreetLine1>Street Line1</StreetLine1>
<City>City Name</City>
<StateCode>AE</StateCode>
<PostalCode>12345</PostalCode>
</Address>
</Resident>
<Resident>
<Name>Sample Name1</Name>
<PhoneNumber>1234567891</PhoneNumber>
<EmailAddress>sample_name1#example.com</EmailAddress>
<Address>
<StreetLine1>Current Address</StreetLine1>
<City>Los Angeles</City>
<StateCode>CA</StateCode>
<PostalCode>56666</PostalCode>
</Address>
</Resident>
<Resident />
</State>

As other writes, you should not use sed, but if you have no other option.
sed 's/ Id=".*"//' file
<State>
<Resident>
<Name>Sample Name</Name>
<PhoneNumber>1234567891</PhoneNumber>
<EmailAddress>sample_name#example.com</EmailAddress>
<Address>
<StreetLine1>Street Line1</StreetLine1>
<City>City Name</City>
<StateCode>AE</StateCode>
<PostalCode>12345</PostalCode>
</Address>
</Resident>
<Resident>
<Name>Sample Name1</Name>
<PhoneNumber>1234567891</PhoneNumber>
<EmailAddress>sample_name1#example.com</EmailAddress>
<Address>
<StreetLine1>Current Address</StreetLine1>
<City>Los Angeles</City>
<StateCode>CA</StateCode>
<PostalCode>56666</PostalCode>
</Address>
</Resident>
<Resident />
</State>

Related

Generate Odoo11 Custom Reports with Wizard. Format error: Not a PDF or corrupted

i'm trying to print an Odoo custom report based on a wizard.
it takes inputs from a wizard view. The wizard lets the user select a project with start_date and end_date. and click print button. so the list of activities that match the wizard form fields filter should be printed in a PDF. but i got a PDF file with 0 KB and when i try to open i get Format error: Not a PDF or corrupted. and there is no errors in console
Here is some key files
reports/__init__.py
# -*- coding: utf-8 -*-
from odoo import models, api
class ReportWorkPlan(models.AbstractModel):
_name = 'ewonga_pta.report_model_work_plan'
#api.model
def render_html(self, docids, data=None):
docs = self.env['ew.pta.line'].browse(docids)
docargs = {
"doc_ids": docs.ids,
"doc_model": "ew.pta.line",
"docs": docs,
}
return docargs
reports/print_work_plan_template.xml
<?xml version="1.0" ?>
<odoo>
<template id="report_work_plan_template">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="web.external_layout">
<div class="page">
<h2>Report title</h2>
</div>
</t>
</t>
</t>
</template>
</odoo>
reports/work_plan_report.xml
<?xml version="1.0" ?>
<odoo>
<report
id="action_work_plan_print_report"
string="Print Report"
model="ewonga_pta.report_model_work_plan"
report_type="qweb-pdf"
name="ewonga_pta.report_work_plan_template"
file="print_work_plan_template"
/>
</odoo>
wizards/workplan.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class WorkPlanWizard(models.TransientModel):
_name = "ewonga_pta.work_plan_wizard"
# attendee_ids = fields.Many2many('res.partner', string="Attendees")
project_id = fields.Many2one("account.analytic.account", domain=[("type_interne", "=", "projet" )])
start_date = fields.Date("Date de début")
end_date = fields.Date("Date de fin")
#api.multi
def check_report(self):
data = {}
data["form"] = self.read(
[
"project_id",
"start_date",
"end_date"
]
)[0]
return self.env.ref("ewonga_pta.action_work_plan_print_report").report_action(self, data=data)
wizards/wizard_work_plan.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="action_work_plan_wizard_action" model="ir.actions.act_window">
<field name="name">Generate Workplan Report</field>
<field name="res_model">ewonga_pta.work_plan_wizard</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="work_plan_wizard_form_view"/>
<field name="target">new</field>
</record>
<record model="ir.ui.view" id="work_plan_wizard_form_view">
<field name="name">work_plan_wizard.form</field>
<field name="model">ewonga_pta.work_plan_wizard</field>
<field name="arch" type="xml">
<form string="Add Attendees">
<group col="4" colspan="4">
<field name="project_id"/>
<field name="start_date"/>
<field name="end_date"/>
</group>
<group col="4" colspan="4">
<footer>
<button name="check_report" string="Imprimer" type="object" default_focus="1" class="oe_highlight"/>
or
<button string="Annuler" class="oe_link" special="cancel"/>
</footer>
</group>
</form>
</field>
</record>
</odoo>
os: Window 10 x64
python: version 3.6.5
wkhtmltopdf: version 0.12.3.2 (with patched qt)
please help me to solve this issues. Thanks
Try to remove your "data" parameters pass thru "report_action" call. Self already contain datas.
Thanks

XMLSlartlet Grep xml node and replace

how to find blocks of node and replace by custom block using xmlstarlet
Below my xml sample:
<?xml version="1.0" encoding="UTF-8"?>
<job>
<input>
<par_denominator nil="true"/>
<par_follow_source>true</par_follow_source>
<par_numerator nil="true"/>
<deblock_enable>Auto</deblock_enable>
<deblock_strength>0</deblock_strength>
<no_psi>false</no_psi>
</input>
<h264_settings>
<par_denominator nil="true"/>
<par_follow_source>true</par_follow_source>
<par_numerator nil="true"/>
</h264_settings>
</job>
I'd like to replace all the block contains
<par_denominator nil="true"/>
<par_follow_source>true</par_follow_source>
<par_numerator nil="true"/>
replacement value
<par_denominator>1</par_denominator>
<par_follow_source>false</par_follow_source>
<par_numerator>1</par_numerator>
xmlstarlet solution:
xmlstarlet ed -u '//*["par_denominator" or "par_numerator"][#nil="true"]' -v 1 \
-u '//par_follow_source[.="true"]' -v 'false' \
-d '//*["par_denominator" or "par_numerator"]/#nil' input.xml
The output:
<?xml version="1.0" encoding="UTF-8"?>
<job>
<input>
<par_denominator>1</par_denominator>
<par_follow_source>false</par_follow_source>
<par_numerator>1</par_numerator>
<deblock_enable>Auto</deblock_enable>
<deblock_strength>0</deblock_strength>
<no_psi>false</no_psi>
</input>
<h264_settings>
<par_denominator>1</par_denominator>
<par_follow_source>false</par_follow_source>
<par_numerator>1</par_numerator>
</h264_settings>
</job>

How access nested child attributes from a list in Adobe AEM using sightly?

I am trying to access a list of items having 'title' and 'url' in them. I want to access the 'item' or 'url' but not sure how to.
The child items are accessible but with:
${child} // prints like this {"title":"Hello","url":"www.hello.com"}
but ${child.url} or ${child['url'} doesn't print anything.
This is my html:
<div data-sly-use.model="au.com.nbnco.website.model.components.Links">
<h6>${properties.linksTitle # context="html"}</h6>
<ul data-sly-list.child="${properties.links}">
<li> ${child.url}</li> // not printing anything
<li> ${child.['url']}</li> // not printing anything
<li> ${child}</li> // prints like this {"title":"Hello","url":"www.hello.com"}
</ul>
</div>
And this my dialog.xml.
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="cq:Dialog"
width="640"
height="480"
xtype="dialog">
<items
jcr:primaryType="cq:Widget"
xtype="tabpanel">
<items jcr:primaryType="cq:WidgetCollection">
<configurations
jcr:primaryType="cq:Panel"
title="Configuration">
<items jcr:primaryType="cq:WidgetCollection">
<links_title
jcr:primaryType="nt:unstructured"
fieldLabel="Links Title"
name="./linksTitle"
defaultValue="Links"
xtype="textfield"/>
<links
jcr:primaryType="cq:Widget"
name="./links"
title="Links"
xtype="multifield">
<fieldConfig
jcr:primaryType="cq:Widget"
border="true"
layout="form"
padding="5px"
xtype="multi-field-panel">
<items jcr:primaryType="cq:WidgetCollection">
<title
jcr:primaryType="cq:Widget"
dName="title"
fieldLabel="Title"
xtype="textfield"/>
<url
jcr:primaryType="cq:Widget"
dName="url"
fieldLabel="Url"
xtype="textfield"/>
</items>
</fieldConfig>
</links>
</items>
</configurations>
</items>
</items>
</jcr:root>
You should be able to access properties url and title like this:
<ul data-sly-list.child="${properties.links}">
<li> ${child.properties.url}</li>
<li> ${child.properties.title}</li>
</ul>
very similar to how you accessed your other custom property "links" of currentPage
It looks like the links property is stored as multiple JSON strings. HTL/Sightly does not parse into JSON strings. You will need a use-api object to parse the JSON and output the properties.
HTL doesn't parse your objects. You can use a JS helper function to parse your elements.
<sly data-sly-list.jsonLinks="${properties.links}">
<ul data-sly-use.parsedLinks="${'../parseMyJson.js' # element=jsonLinks}">
<li>${parsedLinks.title}</li>
<li>${parsedLinks.url}</li>
</ul>
</sly>
And in the parent folder for example, create a parseMyJson.js with :
use(function () {
var element = this.element;
if (element) {
element = JSON.parse(element);
}
return element;
});

Population data xquery

For the XML data below I am trying to get the output shown here: I.e I want to see the names of the countries having a population greater than 20000 , with the conditions that the number of cities displayed should only be for those with a population more than 3500. Also, For some countries the city is within a province.
<result>
<country name="B">
<num_cities>3</num_cities>
</country>
<country name="C">
<num_cities>2</num_cities>
</country>
</result>
---------------------------This is the XML data----------------------
<country id="1" name="A" population="12000">
<name>A</name>
<city id="c1" country="1">
<name>T1</name>
<population>5000</population>
</city>
<city id="c2" country="1">
<name>T2</name>
<population>3000</population>
</city>
<city id="c3" country="1">
<name>T3</name>
<population>4000</population>
</city>
</country>
<country id="3" name="B" population="80000">
<name>B</name>
<city id="c4" country="2">
<name>T4</name>
<population>6000</population>
</city>
<city id="c5" country="2">
<name>T5</name>
<population>2000</population>
</city>
<city id="c6" country="2">
<name>T6</name>
<population>60000</population>
</city>
<city id="c7" country="2">
<name>T7</name>
<population>12000</population>
</city>
</country>
<country id="3" name="C" population="68000">
<name>C</name>
<province>P1</province>
<city id="c8" country="3">
<name>T8</name>
<population>51000</population>
</city>
<city id="c9" country="3">
<name>T9</name>
<population>3000</population>
</city>
<city id="c10" country="3">
<name>T10</name>
<population>14000</population>
</city>
</country>
I wrote this xquery but i don't know how to exclude the cities having a population > 3500. I might not have written to code correctly either...Please assist.
for $c in doc("abc")//country
let $city:= count($c/city/name)
let $citypr:= count($c/province/city/name)
where $c/#population>1000000
return
<result>
<country name='{data($c/name) }'></country>
<num_of_cities>
{
if (exists ($c/city/name)) then
$city
else
$citypr
}
</num_of_cities>
</result>
Some hints:
Don't bother with where clauses where you can filter down earlier, in a specifier retrieving your content.
If you want to have only one <result>, rather than one per datum, you need to start it before the FLWOR expression; whatever you 'return' will be returned once per item.
This is an example of something closer:
<result>{
for $large-country in doc("abc")//country[#population > 20000]
let $large-cities := $country/city[population > 3500]
return
<country name="{$large-country/#name}">
<num_cities>{count($large-cities)}</num_cities>
</country>
}</result>

How do I take returned XML and insert specific elements into columns in SQL Server using VB?

I have a SQL Server database, and I need to populate it with returned xml from an api call.
This is the xml code that's returned(not in a file):
<petfinder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://api.petfinder.com/schemas/0.9/petfinder.xsd">
<header>
<version>0.1</version>
<timestamp>2013-04-08T14:52:23Z</timestamp>
<status>
<code>100</code>
<message/>
</status>
</header>
<lastOffset>25</lastOffset>
<pets>
<pet>
<id>18589607</id>
<shelterId>OK98</shelterId>
<shelterPetId>11C-0015</shelterPetId>
<name>Sam</name>
<animal>Cat</animal>
<breeds>
<breed>Domestic Short Hair</breed>
<breed>Tabby</breed>
</breeds>
<mix>yes</mix>
<age>Adult</age>
<sex>M</sex>
<size>XL</size>
<options>
<option>altered</option>
<option>hasShots</option>
<option>housebroken</option>
</options>
<description>
<![CDATA[
<div>This guy loves the camera. Look at him pose and show off! Sam is about 5 years old and is a cream Tabby. He is good with other cats and is house trained. He has turquoise eyes and is a sweet sweet cat. Sam loves to be the right hand man and assist you on any task you may have. Sammy is not the type of cat that likes to be held but will sit right next to you for some rubbing and head butting. Our adoption fee is $100 for dogs and $75 for cats. This adoption fee includes the spay or neutering and rabies shot. </div>
]]>
</description>
<lastUpdate>2012-07-24T14:50:17Z</lastUpdate>
<status>A</status>
<media>
<photos>
<photo id="1" size="x">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-1-x.jpg
</photo>
<photo id="1" size="fpm">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-1-fpm.jpg
</photo>
<photo id="1" size="pn">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-1-pn.jpg
</photo>
<photo id="1" size="pnt">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-1-pnt.jpg
</photo>
<photo id="1" size="t">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-1-t.jpg
</photo>
<photo id="2" size="x">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-2-x.jpg
</photo>
<photo id="2" size="fpm">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-2-fpm.jpg
</photo>
<photo id="2" size="pn">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-2-pn.jpg
</photo>
<photo id="2" size="pnt">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-2-pnt.jpg
</photo>
<photo id="2" size="t">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-2-t.jpg
</photo>
<photo id="3" size="x">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-3-x.jpg
</photo>
<photo id="3" size="fpm">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-3-fpm.jpg
</photo>
<photo id="3" size="pn">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-3-pn.jpg
</photo>
<photo id="3" size="pnt">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-3-pnt.jpg
</photo>
<photo id="3" size="t">
http://photos.petfinder.com/photos/US/OK/OK98/18589607/OK98.18589607-3-t.jpg
</photo>
</photos>
</media>
<contact>
<address1>714 Martin Luther King Jr Ave</address1>
<address2/>
<city>Duncan</city>
<state>OK</state>
<zip>73533</zip>
<phone/>
<fax/>
<email/>
</contact>
</pet>
...
More specifically, I need to take the nodes for ID, name, animal, description, and several others, and insert them into their respectful columns in my database.
And it must repeat this for each "pet" node that these are all in.
Can I do this in VB.net without saving a file, just as an xml string?
Please help, I've been stuck on this for days.
Assuming you have your XML structure in a variable (or stored procedure parameter) of type XML, you can do something like this:
CREATE PROCEDURE dbo.InsertXmlData
#XmlData XML
AS BEGIN
INSERT INTO dbo.YourTable(ID, PetName, Animal, Description)
SELECT
ID = Pet.value('(id)[1]', 'int'),
PetName = Pet.value('(name)[1]', 'varchar(50)'),
Animal = Pet.value('(animal)[1]', 'varchar(50)'),
[Description] = Pet.value('(description)[1]', 'varchar(500)')
FROM
#XmlData.nodes('/petfinder/pets/pet') AS xTBL(Pet)
END
That gives you the info in those nodes as a set of rows and columns which you can easily insert into a SQL Server table. So now you just need to find a way to call this stored procedure from your VB.NET code and pass in the XML into the #XmlData parameter
Here's an example of how you can extract the data for each pet from the XML using XPath and the XmlDocument class:
Dim doc As XmlDocument = New XmlDocument()
doc.LoadXml(xmlString)
For Each pet As XmlNode In doc.SelectNodes("/petfinder/pets/pet")
Dim id As String = pet.SelectSingleNode("id").InnerText
Dim name As String = pet.SelectSingleNode("name").InnerText
' ...
Next
I'm assuming you know how to save the data to your SQL database from there.

Resources