for the following document
<root>
<child no=1>
<grandchild no=1></grandchild>
<grandchild no=2></grandchild>
<grandchild no=3></grandchild>
</child>
<child no=2>
<grandchild no=1></grandchild>
<grandchild no=2></grandchild>
<grandchild no=3></grandchild>
<grandchild no=4></grandchild>
</child>
</root>
how can I select all children together with only their respective first two grandchildren? I.e. I'd like to return
<child no=1>
<grandchild no=1></grandchild>
<grandchild no=2></grandchild>
</child>
<child no=2>
<grandchild no=1></grandchild>
<grandchild no=2></grandchild>
</child>
My attempt //child/grandchild[#no=1 or #no=2] only gives me
<grandchild no=1></grandchild>,
<grandchild no=2></grandchild>,
<grandchild no=1></grandchild>,
<grandchild no=2></grandchild>
i.e. grandchildren are no longer contained in their respective children.
Many thanks for suggestions and pointers!
bb
Xpath is used to select the tag in the xml, not modify it. you want modify the child tag and xpath can not do it.
But you can use lxml or xml library to parse the xml and modify it.
Related
Is it possible to concatenate two nodes variables using Bash ?
i'm trying to contacted this 4 variables
To have something like "5216997, Yes, Mark, Request"
IncidentId="$(echo "cat /incidents/incident/id/text()" | xmllint --nocdata --shell ~/Desktop/Chicago.csv | sed '1d;$d')"
is_customer_satisfied="$(echo "cat /incidents/incident/is_customer_satisfied/text()" | xmllint --nocdata --shell ~/Desktop/Chicago.csv | sed '1d;$d')"
requester="$(echo "cat /incidents/incident/requester/name/text()" | xmllint --nocdata --shell ~/Desktop/Chicago.csv | sed '1d;$d')"
category="$(echo "cat /incidents/incident/category/name/text()" | xmllint --nocdata --shell ~/Desktop/Chicago.csv | sed '1d;$d')"
BUT i do have this :
5216172 ------- 5215298 | ------- Yes ------- Yes | ------- Mark ------- Luc | ------- Request ------- Request
OR is this a better way to do, what i'm looking for ?
And the csv file content xml values :
> <?xml version="1.0" encoding="UTF-8"?>
<incidents>
<incident>
<id>5237425</id>
<number>5101</number>
<name>Google Mail Password Reset</name>
<description></description>
<description_no_html></description_no_html>
<state>Closed</state>
<priority>Low</priority>
<category>
<id>371032</id>
<name>Software</name>
<default_tags>Software</default_tags>
<children>
<child>
<id>505786</id>
<name>Accounts</name>
<default_tags>Google, google, gmail, AppleId, appleid, Uniflow, </default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
<child>
<id>371040</id>
<name>Email/Outlook</name>
<default_tags>Mail/Outlook, Email, Outlook</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
<child>
<id>423866</id>
<name>iOS</name>
<default_tags>iOS</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
<child>
<id>371044</id>
<name>macOS</name>
<default_tags>macOS</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
<child>
<id>371043</id>
<name>MS office (Word, Excel,...)</name>
<default_tags>MS office, Word, Excel, Access</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
<child>
<id>371047</id>
<name>Other Software</name>
<default_tags>Other Software</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
<child>
<id>371046</id>
<name>Windows</name>
<default_tags>Windows</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</child>
</children>
<parent_id nil="true"/>
<default_assignee_id>-1</default_assignee_id>
</category>
<subcategory>
<id>371040</id>
<name>Email/Outlook</name>
<default_tags>Mail/Outlook, Email, Outlook</default_tags>
<children nil="true"/>
<parent_id>371032</parent_id>
<default_assignee_id>-1</default_assignee_id>
</subcategory>
<assignee>
<group_id>1518184</group_id>
<is_user>true</is_user>
<id>1323154</id>
<name>Mark</name>
<disabled>false</disabled>
<title>IT Support Administrator</title>
<created_at>2017-01-30T16:06:46+01:00</created_at>
<last_login>2018-03-01T09:23:45+01:00</last_login>
<phone> 22</phone>
<mobile_phone> 36</mobile_phone>
<department>
<id>20501</id>
<name>IT</name>
<description>IT Team</description>
<default_assignee_id>-1</default_assignee_id>
</department>
<role>
<id>233084</id>
<name>IT support</name>
<description></description>
<portal>false</portal>
<show_my_tasks>false</show_my_tasks>
</role>
<salt>0ec80dd90d499c4e80307fd8128f6e267717ae9b</salt>
<group_ids>
<group_id>1518184</group_id>
<group_id>1499663</group_id>
<group_id>1539645</group_id>
</group_ids>
<custom_fields_values/>
<avatar>
<type>initials</type>
<color>#0bc46f</color>
<initials>ML</initials>
</avatar>
<mfa_enabled>false</mfa_enabled>
<reports_to>
<group_id>1500982</group_id>
<is_user>true</is_user>
<id>1308247</id>
<name>Stéphane</name>
<disabled>false</disabled>
<title>IT Support</title>
<email>user#test.com</email>
<created_at>2016-10-21T09:55:42+02:00</created_at>
<last_login>2018-05-28T08:04:33+02:00</last_login>
<phone> 47 95</phone>
<mobile_phone>+41 14 24</mobile_phone>
<department>
<id>20501</id>
<name>IT</name>
<description>IT Team</description>
<default_assignee_id>-1</default_assignee_id>
</department>
<role>
<id>225674</id>
<name>Administrator</name>
<description>This is the all powerful administrator user!</description>
<portal>false</portal>
<show_my_tasks>false</show_my_tasks>
</role>
<salt>bde321c1b90d43d1af1b12140ad2528cadc69672</salt>
<group_ids>
<group_id>1500982</group_id>
</group_ids>
<custom_fields_values/>
<avatar>
<type>image</type>
<image_class>avatar_image</image_class>
<sso_image_class></sso_image_class>
<avatar_url></avatar_url>
</avatar>
<mfa_enabled>false</mfa_enabled>
<site>
<id>23927</id>
<name>IT</name>
<location>London</location>
<description>London</description>
<time_zone>Bern</time_zone>
<language>-1</language>
<business_record>
<id>28860</id>
<name>Default Business Hours</name>
<description>This is your initial business hours record</description>
</business_record>
</site>
</reports_to>
<site>
<id>23926</id>
<name>London</name>
<location>london</location>
<description>London</description>
<time_zone>Bern</time_zone>
<language>-1</language>
<business_record>
<id>28860</id>
<name>Default Business Hours</name>
<description>This is your initial business hours record</description>
</business_record>
</site>
</assignee>
<requester>
<id>1157306</id>
<account_id>34933</account_id>
<user_id>1393446</user_id>
<email>user#london.com</email>
<name>Student - Leysin</name>
<disabled>false</disabled>
<has_gravatar>false</has_gravatar>
<customer_satisfaction_survey_time>2018-06-08T15:01:57+02:00</customer_satisfaction_survey_time>
<avatar>
<type>initials</type>
<color>#bb5bac</color>
<initials>SL</initials>
</avatar>
</requester>
<created_at>2018-06-26T11:12:32+02:00</created_at>
<updated_at>2018-06-26T11:12:32+02:00</updated_at>
<due_at nil="true"/>
<sla_violations/>
<number_of_comments>0</number_of_comments>
<user_saw_all_comments>true</user_saw_all_comments>
<is_service_request>false</is_service_request>
<created_by>
<id>1089626</id>
<account_id>34933</account_id>
<user_id>1323154</user_id>
<email>user#test.com</email>
<name>Mark</name>
<disabled>false</disabled>
<has_gravatar>false</has_gravatar>
<customer_satisfaction_survey_time>2018-06-27T11:10:20+02:00</customer_satisfaction_survey_time>
<avatar>
<type>initials</type>
<color>#0bc46f</color>
<initials>ML</initials>
</avatar>
</created_by>
<custom nil="true"/>
<href>https://website.com/incidents/5237425-reset.xml</href>
<site>
<id>23926</id>
<name>London</name>
<location>London</location>
<description>London</description>
<time_zone>Bern</time_zone>
<language>-1</language>
<business_record>
<id>28860</id>
<name>Default Business Hours</name>
<description>This is your initial business hours record</description>
</business_record>
</site>
<department>
<id>26020</id>
<name>Students</name>
<description>Students</description>
<default_assignee_id>-1</default_assignee_id>
</department>
<cc/>
<custom_fields_values/>
<comments/>
<attachments/>
<statistics>
<statistic>
<statistic_type>State Changed</statistic_type>
<time>00:01</time>
<time_elapsed>00:01</time_elapsed>
<business_time_elapsed>00:01</business_time_elapsed>
<value>2018-06-26 09:12:32 UTC</value>
</statistic>
<statistic>
<statistic_type>first_touch_resolution</statistic_type>
<time nil="true"/>
<time_elapsed nil="true"/>
<business_time_elapsed nil="true"/>
<value>t</value>
</statistic>
</statistics>
<tags>
<tag>
<id>299260</id>
<name>software</name>
<taggings_count>9349</taggings_count>
</tag>
</incident>
</incidents>
I used xmlstarlet and it works better
I define saiku(3.8) schema as below:
<?xml version="1.0" encoding="utf-8"?>
<Schema name="Zeus Offline Data" metamodelVersion='4.0'>
<PhysicalSchema>
<Table name="ZEUS_OFFLINE_DATA">
<Key>
<Column name='FB_ACCOUNT_ID'/>
</Key>
</Table>
</PhysicalSchema>
<Cube name="OfflineData">
<Dimensions>
<Dimension name="AdAccount" table="ZEUS_OFFLINE_DATA">
<Attributes>
<Attribute name="account_id" keyColumn="FB_ACCOUNT_ID" hasHierarchy="true"/>
</Attributes>
</Dimension>
<Dimension name="BM" table="ZEUS_OFFLINE_DATA">
<Attributes>
<Attribute name="bm_id" keyColumn="BM_ID" hasHierarchy="true"/>
</Attributes>
</Dimension>
</Dimensions>
<MeasureGroups>
<MeasureGroup name="Stats" table="ZEUS_OFFLINE_DATA">
<Measures>
<Measure name="clicks" column="CLICKS" aggregator="sum" formatString="#,###"/>
</Measures>
<DimensionLinks>
<FactLink dimension="AdAccount"/>
<FactLink dimension="BM"/>
</DimensionLinks>
</MeasureGroup>
</MeasureGroups>
It contains two dimension "bm_id" and "fb_account_id", and one measure "clicks".In database backend, bm_id and fb_account_id are int type. When I make query in Saiku, the result of bm_id and fb_account_id are shown in scientific notation mode, which I don't want.
Result:
bm_id clicks
1.71141391154125E14 1,091,234
Which I want:
171141391154125 1,091,234
I don't know which attribute should be changed for that, any help appreaciated
Thanks
I have below XML
<response>
<data-table filter="XXX" count="26">
<columns>
<column>sampm</column>
<column>sampn</column>
</columns>
<rows>
<row attr="535545">
<field>sampx</field>
<field>sampy</field>
</row>
<row attr="535548">
<field>samp1</field>
<field>samp2</field>
</row>
</rows>
</data-table>
</response>
From this response I have to loop over rows i.e; /response/data-table/rows/row
So here is my mule code snippet with for each
<http:request config-ref="HTTP_REQUEST" path="api/query" method="GET" doc:name="HTTP" followRedirects="true">
</http:request>
<object-to-string-transformer doc:name="Object to String"/>
<foreach collection="#[xpath3('//response/data-table/rows')]" doc:name="For Each">
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</foreach>
But I am getting a warning "The expression does not evaluate to a type that can be split: java.lang.String"
Is there any work around this problem
Rows would return you an object, try changing your expression to xpath3('//query-response/data-table/rows/row')
Specify the xpath3 return type to be a NODESET:
<foreach
collection="#[xpath3('//query-response/data-table/rows', payload, 'NODESET')]"
This should be iterable.
Just little help. Please let me know the correct xpath expression for this
I have xml doc like this
<parent>
<child id='1' show='true' />
<child id='2' show='true' />
<child id='3' show='true' />
<child id='4' show='true' />
<child id='5' show='true' />
<child id='6' show='true' />
</parent>
I want to select all show attributes except 2nd and 5th childs so that i can turn their values to false
You can use boolean and in your XPath expression:
/parent/child[#id != '2' and #id != '5']
If you really want the second and fifth element, you can use the position() function:
/parent/child[position() != 2 and position() != 5]
Use:
/*/*[not(position() = 2 or position() = 5)]/#show
This selects any show attribute of any child of the top element of the xml document, that isn't the second or the fifth child of its parent.
So I have one RelaxNG schema that references another:
<define name="review">
<element name="review">
<externalRef href="other.rng"/>
</element>
</define>
other.rng:
<start>
<choice>
<ref name="good"/>
<ref name="bad"/>
</choice>
</start>
<define name="good">
<element name="good"/>
</define>
<define name="bad">
<element name="bad"/>
</define>
Is there any way I can import only <good>, but not allow <bad>? The goal being:
<review><good/></review>: valid
<review><bad/></review>: invalid
The grammar you import with externalRef can't be modified. To achieve the kind of validation you're after, I see this method :
<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<include href="other.rng">
<start combine="choice">
<ref name="review"/>
</start>
</include>
<define name="review">
<element name="review">
<ref name="good"/>
</element>
</define>
</grammar>
You include the other schema.
You override the start element in the include (good and bad elements won't be possible root).
The specification says :
If the include element has a start component, then all start
components are removed from the grammar element.
You make a reference to the good element in your review definition.