How to insert this xml data to mysql using LOAD XML - mysql

<?xml version="1.0" encoding="UTF-8"?>
<jobs>
<job>
<location>Raleigh, NC, US</location>
<title>Implementation Consultant II</title>
<city>Raleigh</city>
<job_type/>
</job>
<job>
<location>Saint Louis, MO, US</location>
<title>Food Service Worker I</title>
<city>Raleigh</city>
<job_type> Permanent </job_type>
</job>
</jobs>
Here i cant able to insert the data for job_type into mysql using LOAD DATA LOCAL INFILE

It's a bug in MySQL. Upgrade to MySQL 5.5.46 or higher.
From official documentation:
Prior to MySQL 5.5.46, LOAD XML did not handle empty XML elements in
the form correctly. (Bug #67542, Bug #16171518)

Related

How to get rid of Liquibase includeAll tag with formatted .sql changesets error: Cannot find the declaration of element 'databaseChangeLog'

I am using a Gradle Spring project with liquibase. To run liquibase I am running the jar created by compiling the project. I am trying to use the liquibase "includeAll" tag in an xml changelog to run all formatted sql changelog scripts inside a directory I've called includeAllScriptsTest (currently contains only one .sql file named test.sql with one changeset).
If I try to use includeAll in my master db-changelog file, at run time liquibase returns the error: file:///.../conf/db/db.changelog-master.xml/ is not a recognized file type.
In an attempt to get around this, I reference from my db-changelog-master.xml another xml called includeAll-changelog.xml. In this file I have the includeAll tag, below are the contents of this file.
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="https://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog conf/xsd/dbchangelog-3.8.xsd">
<includeAll path="***/includeAllScriptsTest/" relativeToChangelogFile="true"/>
</databaseChangeLog>
Inside the folder includeAllScriptsTest is a single file called test.sql, with the contents as below:
--liquibase formatted sql
--changeset author:1 dbms:MySQL splitStatements:true endDelimiter://
DROP PROCEDURE IF EXISTS `TESTINCLUDEALL`;//
CREATE PROCEDURE `TESTINCLUDEALL`()
BEGIN
SELECT * FROM TABLE;
END;//
However, this gives me a different error at run time: cvc-elt.1.a: Cannot find the declaration of element 'databaseChangeLog'. I've found online conflicting information regarding whether it is possible to use includeAll with the version of liquibase used by my project. I'm currently using 3.4.1.
cvc-elt.1.a: Cannot find the declaration of element
'databaseChangeLog'
This error is an XML Parsing error, pointing databaseChangeLog is not declared in the xml schema.
May be you can try using following XSD in your changelog:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<includeAll path="***/includeAllScriptsTest/" relativeToChangelogFile="true"/>
</databaseChangeLog>
If this still doesn't help, please have a look at few points in answer on this post.

Read XML data and save them to mysql database in symfony 4

I have a simple XML file. I need to read the data and save them to mysql database table (1 or 2 tables). The file is like following :
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:g="http://">
<myfile>
<title><![CDATA[All data]]></title>
<stock>
<name><![CDATA[my name]]></name>
<qty><![CDATA[0]]></qty>
<price><![CDATA[4.99]]></price>
<image><![CDATA[http://fashiondropshippers.com/media/catalog/product/i/m/image_463.jpg]]></image>
</stock>
</myfile>
</rss>
I am trying to do that in Symfony 4 using crawler. my codes in my controller are following
$crawler = new Crawler();
$crawler->addContent(file_get_contents('http://localhost/XML/myxml.xml'));
foreach ($crawler as $domElement) {
var_dump($domElement->nodeValue);
}
return new JsonResponse($domElement->nodeValue);
It displays data with errors. Now I need to save those data in mysql database tables. Could you please tell me how to proceed further ?
Many thanks in advance !
Ok. If you want to save data to DB you have to do the following:
Add Doctrine to your project: https://symfony.com/doc/current/doctrine.html#installing-doctrine
Create an entity: https://symfony.com/doc/current/doctrine.html#creating-an-entity-class
Make migrations: https://symfony.com/doc/current/doctrine.html#migrations-creating-the-database-tables-schema and execute them
Save your data to DB https://symfony.com/doc/current/doctrine.html#persisting-objects-to-the-database

Load XML into mySQL with diffrent rows ID

I have the following XML file and I need load into mysql using LOAD XML LOCAL INFILE.
I´m using the following line:
LOAD XML LOCAL INFILE 'C:/_BORBA_/xml/importxml.xml' INTO TABLE importxml ROWS IDENTIFIED BY '<ide>'
If I declare "ide" as delimiter, I can import with sucess, but I have to import all tags (ide, info and proc) as one record row.
How can I explicit that I have 3 groups of information into my XML file?
<?xml version="1.0" encoding="utf-8"?>
<infNFe versao="3.10" Id="NFe351710006">
<ide>
<cUF>35</cUF>
<cNF>99999</cNF>
<natOp>Venda de terceiros</natOp>
<indPag>1</indPag>
<mod>55</mod>
<serie>1</serie>
<nNF>888888</nNF>
<dhEmi>2017-10-26T16:50:52-02:00</dhEmi>
</ide>
<info>
<tpNF>1</tpNF>
<idDest>2</idDest>
<cMunFG>3525904</cMunFG>
<tpImp>1</tpImp>
<tpEmis>1</tpEmis>
</info>
<proc>
<cDV>8</cDV>
<tpAmb>1</tpAmb>
<finNFe>1</finNFe>
<indFinal>0</indFinal>
<indPres>9</indPres>
<procEmi>3</procEmi>
<verProc>008</verProc>
<CNPJ>99999888844</CNPJ>
</proc>
</infNFe>
Thank you for any help.

MySQL to MySQL data copy in scriptella

I m trying to use a scriptella script to transfer some data to data in one server to another.
The script looks something like this
<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
<description>
test script
</description>
<properties>
<include href="../config/kpoint-etl.properties"/>
</properties>
<connection id="in" driver="${driver}" url="${url}" user="${user}" password="${password}">
</connection>
<connection id="out" driver="${driver}" url="${url2}" user="${user}" password="${password}">
</connection>
<query connection-id="in">
SELECT owner_name, owner_domain, DATE(time_last_update)
as pdate, count(*) as avg from kapsule where DATE(time_last_update)="2013-06-19" group by owner_name;
<script connection-id="out">
UPDATE test SET username=?owner_name, domain=?owner_domain, frequency=?avg, rdate=?pdate;
</script>
</query>
</etl>
the 'in' connection id seems to be working fine, but on connection to the second server it shows the following error.
JDBC provider exception: Unable to obtain
connection for URL jdbc:/mysql://localhost:3306/leopard
Error codes: [08001, 0]
Driver exception: java.sql.SQLException: No suitable
driver found for jdbc:/mysql://localhost:3306/leopard
The properties file is something like this
driver=mysql
url=jdbc:mysql://192.168.8.72:3306/leopard
user=leopard
password=user12
url2=jdbc:/mysql://localhost:3306/leopard
Any help will be appreciated. Thank You.
P.s. Do ask for any doubts regarding the question.
You have an extra slash in the second url jdbc:/mysql. Try removing it.

Updating an attribute in XML with MySQL

I have a chunk of XML stored as a string in a MySQL database, and need to update one of the attributes using a query.
Given the following string:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<town>
<road name="Main" direction="north"/>
</town>
I would need to change it to update the attribute direction to a different value:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<town>
<road name="Main" direction="east"/>
</town>
Is there an easy way to accomplish this? Thanks in advance!
EDIT: The query would be ran in a SQL script file containing various other upgrade queries, which is called by a piece of code in Java.
Checkout PHP's simple XML
http://www.php.net/manual/en/class.simplexmlelement.php
$xml=new SimpleXMLElement($xml);
print $xml->road->attributes('direction') = 'east';
I ended up overriding the upgrade process for that version. Through Java and JDBC I looped through every row and used JAXB to gain access to the attribute that needed to be changed. I would have preferred to do it with full SQL queries. :(