XML to HTML Conversion for complex xml - html

I am trying to convert a big xml file to html.
I have pest the part of xml file here.
in the xml file there are repetitive tags.
like header tag can be multiple time present in xml.
but inside body tag there is only one header tag.
Inside header tag there is another sub tag and I want to get all the value like Employee_B_ID, Login ID, Hire Date, Rate and display as a tabular format.
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.23" id="1">
------
----
-----
<body>
<image id="258">
<property name="height">0.9375in</property>
<property name="width">3.5104166666666665in</property>
<property name="source">embed</property>
<property name="imageName">logo-new - Copy.jpg</property>
</image>
<label id="245">
<property name="fontFamily">sans-serif</property>
<property name="fontSize">x-large</property>
<property name="fontWeight">bold</property>
<property name="textAlign">center</property>
<text-property name="text">Employee Information</text-property>
</label>
<table id="163">
<property name="width">100%</property>
<property name="dataSet">Data Set</property>
<property name="refTemplateParameter">NewTemplateParameterDefinition2</property>
<list-property name="paramBindings">
<structure>
<property name="paramName">b_id</property>
<simple-property-list name="expression">
<value type="javascript">params["b_id"]</value>
</simple-property-list>
</structure>
</list-property>
<list-property name="boundDataColumns">
<structure>
<property name="name">BusinessEntityID</property>
<text-property name="displayName">BusinessEntityID</text-property>
<expression name="expression" type="javascript">dataSetRow["BusinessEntityID"]</expression>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="name">LoginID</property>
<text-property name="displayName">LoginID</text-property>
<expression name="expression" type="javascript">dataSetRow["LoginID"]</expression>
<property name="dataType">string</property>
</structure>
<structure>
<property name="name">HireDate</property>
<text-property name="displayName">HireDate</text-property>
<expression name="expression" type="javascript">dataSetRow["HireDate"]</expression>
<property name="dataType">string</property>
</structure>
<structure>
<property name="name">Rate</property>
<text-property name="displayName">Rate</text-property>
<expression name="expression" type="javascript">dataSetRow["Rate"]</expression>
<property name="dataType">decimal</property>
</structure>
</list-property>
<property name="pageBreakInterval">50</property>
<column id="187"/>
<column id="188"/>
<column id="189"/>
<column id="190"/>
<header>
<row id="164">
<cell id="165">
<label id="166">
<property name="fontFamily">sans-serif</property>
<property name="fontWeight">bold</property>
<text-property name="text">Employee_B_ID</text-property>
</label>
</cell>
<cell id="167">
<label id="168">
<property name="fontFamily">sans-serif</property>
<property name="fontWeight">bold</property>
<text-property name="text">Login ID</text-property>
</label>
</cell>
<cell id="169">
<label id="170">
<property name="fontFamily">sans-serif</property>
<property name="fontWeight">bold</property>
<text-property name="text">Hire Date</text-property>
</label>
</cell>
<cell id="171">
<label id="172">
<property name="fontFamily">sans-serif</property>
<property name="fontWeight">bold</property>
<text-property name="text">Rate</text-property>
</label>
</cell>
</row>
</header>
<detail>
<row id="173">
<cell id="174">
<data id="250">
<property name="resultSetColumn">BusinessEntityID</property>
</data>
</cell>
<cell id="176">
<data id="251">
<property name="resultSetColumn">LoginID</property>
</data>
</cell>
<cell id="178">
<data id="252">
<property name="resultSetColumn">HireDate</property>
</data>
</cell>
<cell id="180">
<data id="253">
<property name="resultSetColumn">Rate</property>
</data>
</cell>
</row>
</detail>
<footer>
<row id="182">
<cell id="183"/>
<cell id="184"/>
<cell id="185"/>
<cell id="186"/>
</row>
</footer>
</table>
</body>
-------
-----
----
</report>
How to retrieve the value which is inside
<body><header><text-property name="text">Employee_B_ID</text-property>
I need to display Employee_B_ID, Login ID, Hire Date, Rate as a tabular format.
can any one help me please.
Thanks
Ashim

You can use an XML parser and your favourite programming language. For different languages there are different libraries capable to parse xml for instance JAXB in java or REXML in ruby. After you parse the XML it should be relatively easy to do what you want.

Related

Publishing JMS message on Solace Topic

I am facing issue while publishing JMS message on Solace server topic.
Actually we are successfully able to send message using jmsTemplate.send() method.
But unable to see the message count on solace client GUI.
Below is my solace configuration.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:messaging.properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
<!-- Solace Broker Configuration Details -->
<bean id="solaceJndiTemplate" class="org.springframework.jndi.JndiTemplate"
lazy-init="default" autowire="default">
<property name="environment">
<map>
<entry key="java.naming.provider.url" value="${solace.url}" />
<entry key="java.naming.factory.initial"
value="com.solacesystems.jndi.SolJNDIInitialContextFactory" />
<entry key="java.naming.security.principal" value="${solace.userName}" />
<entry key="java.naming.security.credentials" value="${solace.passWord}" />
</map>
</property>
</bean>
<bean id="solaceConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"
lazy-init="default" autowire="default">
<property name="jndiTemplate" ref="solaceJndiTemplate" />
<property name="jndiName" value="${solace.jndiName}" />
</bean>
<!-- <bean id="solaceCachedConnectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="solaceConnectionFactory" />
<property name="sessionCacheSize" value="10" />
</bean> -->
<bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="solaceJndiTemplate" />
<property name="jndiName" value="${solace.topic}" />
</bean>
<!-- <bean id="topicDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="solaceJndiTemplate" />
<property name="jndiName" value="${solace.topic}" />
</bean> -->
<bean id="solaceQueueJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="solaceConnectionFactory" />
<property name="defaultDestination" ref="destination" />
<property name="deliveryPersistent" value="false" />
<property name="explicitQosEnabled" value="true" />
<property name="pubSubDomain" value="false"/>
</bean>
<bean id="solaceTopicJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="solaceConnectionFactory" />
<property name="defaultDestination" ref="destination" />
<property name="deliveryPersistent" value="false" />
<property name="explicitQosEnabled" value="true" />
<property name="pubSubDomain" value="true"/>
</bean>
<bean id="solaceQueueBroker" class="com.isc.common.messaging.SolaceUtilityHelper">
<property name="jmsTemplate" ref="solaceQueueJmsTemplate" />
</bean>
<bean id="solaceTopicBroker" class="com.isc.common.messaging.SolaceUtilityHelper">
<property name="jmsTemplate" ref="solaceTopicJmsTemplate" />
</bean>
<bean id="messageBroker" class="com.isc.common.messaging.SolaceUtilityHelper">
<property name="activeBroker" value="${active.broker}" />
</bean>
<!-- <bean id="messageConsumer" class="com.isc.common.messaging.MessageConsumer">
</bean>
<bean id="jmsContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="solaceCachedConnectionFactory" />
<property name="destination" ref="destination" />
<property name="messageListener" ref="messageConsumer" />
</bean> -->
</beans>
please can any one suggest me solution for this.
Thanks in advance.
Saurabh Mahajan
Based on your comments, it would appear that you are publishing to a topic, but there are no endpoints configured to spool the message.
You can refer to at Adding Topic Subscriptions to Queues for details on how to configure an queue to spool messages that are published to a topic.
To confirm, you can verify whether messages are listed under the "No Subscription Match Logs". In SolAdmin, you can view them by heading to "Logging & Diagnostics" and selecting the "No Subscription Match Logs". The corresponding CLI command for this is show log no-subscription-match
Also, the statistics of your application connection would also display the number of messages received and sent, with any discard reasons. This can be viewed by heading to the "Clients" tab, and selecting the "Client" view. Then, double click on your client and head to "Statistics". Alternatively, the CLI command for this is show client <your-client-name> message-vpn <your-vpn-name> stats

Print XML attribute in SQL Server

I am trying to get value of an attribute from XML in SQL table
<?xml version="1.0" encoding="utf-8"?>
<container>
<Property Name="paramA" Vocabulary="someVocu">
<Property Name="paramB" Value="valueA" />
<Property Name="paramC" Value="valueB" />
</Property>
<Property Name="paramA" Vocabulary="anotherVocu">
<Property Name="paramB" Value="valueY" />
<Property Name="paramC" Value="valueZ" />
</Property>
</container>
select x.XmlCol.value('(Property[#Name="paramB"]/#Value)[1]', 'varchar(50)') from tempTbl CROSS APPLY rawxml.nodes('/container') AS x(XmlCol)
I am trying to print "valueA" and "valueY" I am getting a NULL.
How can I do this?
Thanks
I cannot tell you what in particular is wrong with your statement since I am still learning how to query XML too. I was able to come up with some SQL which I think should work for by referencing this question...
How to query for Xml values and attributes from table in SQL Server?
Here it is.
CREATE TABLE tempTbl
(
id INT,
data XML
)
INSERT INTO dbo.tempTbl
(id, data)
SELECT 1, '<?xml version="1.0" encoding="utf-8"?>
<container>
<Property Name="paramA" Vocabulary="someVocu">
<Property Name="paramB" Value="valueA" />
<Property Name="paramC" Value="valueB" />
</Property>
<Property Name="paramA" Vocabulary="anotherVocu">
<Property Name="paramB" Value="valueY" />
<Property Name="paramC" Value="valueZ" />
</Property>
</container>'
SELECT
x.XmlCol.value('#Value', 'varchar(25)') AS Value
FROM tempTbl AS t
CROSS APPLY t.data.nodes('/container/Property/Property') AS x(XmlCol)
WHERE x.XmlCol.value('#Name', 'varchar(25)') = 'paramB'
To learn more about querying XML I am working through Stairway to XML.
Noel

JPA/Hibernate: Missing table error

I am trying to build a simple application using Hibernate JPA with MySQL but I keep getting a "Missing table" error whenever I try to deploy it to Wildfly.
My persistent class looks like this:
package com.example;
#Entity #Table
public class FooBar {
//...
}
Here is my persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="ExampleJPA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.example.FooBar</class>
<properties>
<!-- Configuring JDBC properties -->
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/mydatabase" />
<property name="javax.persistence.jdbc.user" value="(my user)" />
<property name="javax.persistence.jdbc.password" value="(my password)" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<!-- Hibernate properties -->
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<!-- Configuring Connection Pool -->
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.max_size" value="20" />
<property name="hibernate.c3p0.timeout" value="500" />
<property name="hibernate.c3p0.max_statements" value="50" />
<property name="hibernate.c3p0.idle_test_period" value="2000" />
</properties>
</persistence-unit>
</persistence>
And this is the message I get when deploying to a Wildfly 8 server:
org.jboss.msc.service.StartException in service jboss.persistenceunit.\"ExampleJPA.war#ExampleJPA\": org.hibernate.HibernateException: Missing table: FooBar
Caused by: org.hibernate.HibernateException: Missing table: FooBar
I do have a table called FooBar in the database. I can access it directly with JDBC using the same url, user and password defined in the persistence.xml. What is wrong with my JPA setup?
Your table doesn't exist in the schema, so the hibernate.hbm2ddl.auto value of "validate" fails. Either create the table or change the hibernate.hbm2ddl.auto value to "create" or "update".

bluemix server gives SQLGrammarException in MySQL

![out put from cf logs app-name --recent
]1I have developed a spring/hibernate-MySQL in backend based application. I have tested the application in the local machine successfully. But when I uploaded the app into IBM bluemix, there is exceptions everywhere when I am accessing service-->Dao methods. It says org.hibernate.exception.SQLGrammarException stating the message like " SELECT command denied to user 'username#75.126.83.16'. Interstingly, when I put a normal JSP without Hibernate/spring Dao but by using the same connection string, that works.
Here is the spring-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="pojos" />
<bean id="adminService" class="pojos.AdminService">
<property name="adminDao" ref="adminDao" />
</bean>
.. Other Service class bean's info....
<bean id="adminDao" class="pojos.AdminDao">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="fieldOfficerDao" class="pojos.FieldOfficerDao">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="questionMasterDao" class="pojos.QuestionMasterDao">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
.. Other Dao class bean's info....
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>pojos/Admin.hbm.xml </value>
... And other hbm files...
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://192.155.247.251:3307/<DB-Name>" />
<property name="username" value="<DB-User-Name>" />
<property name="password" value="<DB-Password>" />
</bean>
<bean id="dbUtil"
class="pojos.DbUtil"
init-method="initialize">
<property name="dataSource" ref="dataSource" />
</bean>
I just removed catalog attribute from class tag of each .hbm.xml files. That attribute is optional and it contains schema name of mysQL.
Previously it was
<class name="pojos.Admin" table="admin" catalog="merca">
But Now It is
<class name="pojos.Admin" table="admin">

Spring Security + Hibernate authentication

I have JSF 2.2, Primefaces 3.5, Spring, Spring Security 3.x, Hibernate 4, MySQL web application.
I have enabled Spring Security to work as expected, but I used <user-service/> in which I created two users with different roles ("ROLE_USER", "ROLE_ADMIN"). Now I would like to search for every user in the database, and not to create them manualy in <user-service/>.
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<!-- GLOABL SETTINGS -->
<context:component-scan base-package="com.infostroy.adminportal"/>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<!-- DATA SOURCE AND PERSISTENCE SETTINGS -->
<bean id="propertiesPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:db.properties</value>
</list>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dmDataSource"/>
<property name="packagesToScan" value="com.infostroy.adminportal"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${db.dialect}</prop>
<prop key="hibernate.show_sql">${db.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${db.hbm2ddl_auto}</prop>
<prop key="connection.pool_size">${db.pool_size}</prop>
<prop key="current_session_context_class">${db.current_session_context_class}</prop>
<prop key="org.hibernate.FlushMode">${db.flush_mode}</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="dataSource" ref="dmDataSource" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="dmDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driver}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="maxWait" value="5000" />
<property name="initialSize" value="2" />
<property name="maxActive" value="100"/>
<property name="maxIdle" value="50"/>
<property name="minIdle" value="0"/>
</bean>
</beans>
spring-security.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<http auto-config="false" use-expressions="true">
<intercept-url pattern="/protected/*" access="isAuthenticated()"/>
<form-login login-page="/login.xhtml" login-processing-url="/j_spring_security_check"
default-target-url="/protected/home.xhtml"
authentication-failure-url="/loginFailed.xhtml"/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="c" password="c" authorities="ROLE_ADMIN" />
<user name="q" password="q" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
Here's the script to create users table:
CREATE TABLE users (
user_id INT AUTO_INCREMENT,
first_name VARCHAR(20),
last_name VARCHAR(20),
login VARCHAR(20) NOT NULL UNIQUE,
password VARCHAR(32) NOT NULL,
role VARCHAR(20) NOT NULL,
PRIMARY KEY(user_id)
) ENGINE=InnoDB;
Does anyone know how to achieve this? Every answer is highly appreciated and responded quickly!
Thank you.
Just change the authentication-manager to :
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dmDataSource"
users-by-username-query="
select login as username,password, 1 as enabled
from users where login=?"
authorities-by-username-query="
select login as username, role as authority from users
where login =? "
/>
</authentication-provider>
</authentication-manager>
I assume the login field is the username. I hardcoded the enable flag, it's rquired. If you add deleteflag or enabled flag in the future you can replace it.