How can I select a node from XML datasource by condition?
Eg I have an xml that has multiple customer nodes. I now want to select all the customer whose type=business.
<list>
<customer>
<type>business</type>
<amount>10</amount>
</customer>
<customer>
<type>private</type>
<amount>20</amount>
</customer>
</list>
What is the iReport jrxml expression for this? Do I have to use XPATH to locate the element?
Yes, you should use XPath. Try this one:
/list/customer[type='business']
Related
I'm trying to figure out how to selected all of the Suppliers who do not have TV as a product. I'd also like an explanation on the differences of your answer and what I have.
I have the following query written:
SELECT XMLColumn.query('/SuppliersList/Supplier/Product[not(#name="TV")]/..')
FROM Tb_XPathQueryTable
This is my table, plus a bunch of other Suppliers.
<SuppliersList>
<Supplier name="Joe">
<City>Paris</City>
<Product name="Airplane"/>
<Product name="Milk"/>
<Product name="TV"/>
<Product name="Orange"/>
</Supplier>
On your xpath you are selecting first the Product and then going to its parent, so it will match the specified example (because the TV Product has siblings that match the same parent).
This xpath should work:
/SuppliersList/Supplier[not(Product[#name="TV"])]
As you can see, we are selecting Supplier which doesn't contain a Product child with name="TV"
We have a int-jms:message-driven-channel-adapter --> a transformer --> a filter --> another transformer --> int-jdbc:outbound-channel-adapter (to insert in table_1)
(considering --> as channels)
I want to change this flow to insert into 2 tables instead of 1 but for table_2 I want to insert only if data corresponding to some fields in the message is already not present in the table i.e. insert if not present.
One thing I figured is that I will now need a pub-sub-channel with ignore-failures=false to split the flow into 2 tables.
My question is that what component should I use to select the data to check if data exists in table_2? I first thought inbound-channel-adapter is the right choice but couldn't figure out how to slide it between 2 components i.e. say a transformer and outbound-channel-adapter.
Some things I can think of are:
1. Use a filter, passing it jdbcTemplate so that the filter itself can fire a JDBC query to accept if record doesn't exist.
2. Use a outbound-channel-adapter and the insert query should have the check for data existence also, something like insert-if. I am not sure if Oracle has something like this. I am researching.
Please point me to an example or documentation or tell me the best way.
Thanks
Actually you can use
<chain>
<header-enricher>
<header name="original" expression="payload"/>
</header-enricher>
<int-jdbc:outbound-gateway query="SELECT count(*) from TABLE where ..."/>
<filter expression="payload == 0"/>
<transformer expression="headers.original"/>
</chain>
From other side <filter> with JdbcTemplate direct usage is good choice too.
Re. insert-if. It can work too if you have a unique constraint on the table. In this case an Exception will be thrown. And if you have <publish-subscribe-channel ignore-failures=false>, it would work too.
I know how to parse an xml in oracle which goes something like this
select extractvalue(column_value, 'CIRS/CIR/#applicantId') applicantId
into applicantId
from CIBIL_BINARY_INPUT ,table(xmlsequence(xmltype(ded_enq_xml)))
Now i have an xml as shown below
<library>
<book>
<name>Harry potter</name>
<author>Harry potter</author>
</book>
<book>
<name> watson </name>
<author>Harry watson </author>
</book>
<book>
<name> john </name>
<author> potter</author>
</book>
</library>
As you can see the book node is repeated multiple times
How can i extract it so that i can insert it as 3 different 'book' rows in my library table.
Please suggest.
Seems like your first problem is to extract multiple books from xml. This can be solved like this:
select
extractvalue(column_value, '/book/name') name,
extractvalue(column_value, '/book/author') author
from
table(xmlsequence(extract(xmltype('<library><book>...</book><book>...</book>...</library>'), '/library/book')));
Hope this helps.
On an Oracle database I got a customer table with at Id and Name and so, and a number of customerstuff tables all related a key.
With the Oracle WCF adapter in BizTalk a need to create a file with all the customers and there stuff
Like this:
<Root>
<Customers>
<Customer>
<Id>1</Id>
<Name>A</Name>
<Stuff1>
<data>
.
.
</data>
</Stuff1>
.
.
<Stuff6>
<data>
.
.
</data>
</Stuff6>
</Customer>
<Customer>
<Id>2</Id>
<Name>B</Name>
<Stuff1>
.
.
.
</Stuff6>
</Customer>
</Customers>
</Root>
I started out with a select of all the customers, and in Orchestration I loop over them, selecting from each customerstuff table with the key from the current customer getting me all the data ready for the first customer node in the result file.
Question: how do I build the result file? I have to add the current customer/customerstuff data to the result file, then do a new loop while still holding on to the result file, how can I do that in BizTalk ?
This may be possible with custom XSLT, but I am unsure without seeing more detail about the input and output schemas.
If you go with the looping approach, this is going to require 3 messages
Output Message (your eventual output)
Current Output Placeholder Message (same schema as your eventual output)
Customer Stuff (the data you want to Append to output on a given pass through the loop)
and a map that has two messages to one (or some XPATH based manipulation):
For Each Customer
Create "Customer Stuff"
Copy Output Message to Current Output Placeholder
Perform Map that takes Customer Stuff and Current Output Placeholder Message as input and maps to the "Output Message"
Try using something similar to "for xml" in sql server, when you read the data itself using query or stored procedure. In oracle you can return the result set as xml using dbms_xmlgen package:
select dbms_xmlgen.getxml('select * from emp where rownum <= 2') xmlstr from dual;
I have a migration that will create an index in a table of our Oracle database. The DBA would like the index to be created ONLINE. (Something like CREATE INDEX ..... ONLINE;) Is there something I can add to the tag below to accomplish what I want or do I need to write the SQL into the migration?
<createIndex tableName="USER" indexName="IX_USER_TX_ID">
<column name="TX_ID" />
</createIndex>
There is no standard tag to specify it as ONLINE. Your 3 options to create it as ONLINE are:
Fall back to the tag where you specify the exact SQL you want
Use the modifySql tag to append to the generated SQL.
Create an extension to createIndex that always generates ONLINE at the end of the SQL or adds a parameter to createIndex that allows you to control if it is added or not.
Option #2 is probably the best mix of easy yet flexible and would look something like this:
<changeSet id="1" author="nvoxland">
<createIndex tableName="USER" indexName="IX_USER_TX_ID">
<column name="TX_ID" />
</createIndex>
<modifySql dbms="oracle">
<append value=" ONLINE"/>
</modifySql>
</changeSet>
Notice the space in the value tag. Append does a very simple text append with no built-in logic.