I looked in the MySQL documentation but I didn't find an answer to my question :
I would like to know if MySQL could "check" if a field filled with XML is well formed.
Of course I would give to MySQL a XSD to verify the XML and I will use Spring MVC to manage the server's side of things.
I know it is not something I should do BUT I HAVE to do this in a school project.
rXp
No, MySQL does not provide build-in functions for that. You have to query the document out of the database and use your programming language of choice to validate the XML document against a XSD.
Related
I need help from you experts about practices regarding database development. I have a few questions regarding MySQL databases:
Is there a way for MySQL that a database and its structure is developed in an XML language and then converted to a fully functional MySQL database?
Is it possible to generate the XML source file from question 1 (see above) based on an existing database in MySQL ?
As far as I know, XML is not suitable for developing database structures. However can we say that XML is a language to demonstrate hierarchical structures and a MySQL database also shows a hierarchical structure, so in fact it is suitable for database development?
Thank you very much!
You can certainly store XML data in MySQL. You can also use any number of approaches to converted hierachical XML data into individual relational database field representations.
I would however say that if you just want to work with intact XML documents, you might look to go the NoSQL route, which is really better suited for this type of data storage. You also might consider JSON as the format for storage as it is more concise (saves space and transmissions badnwidth) and is more aligned with the popular NoSQL data stores out there.
1) yeah there is a way, but you should check out mongodb if you want a dynamic database structure, it was developed with that in mind. also, unless you need the rss features of xml or something similar, you might want to consider using json as a format for you documents.
2) json and mongodb work very well together to quickly and easily get documents in and out of the db. you can technically do it in mysql as well, but you might spend more time scripting in php or ruby to get the desired format you want.
3) you could use xml to demonstrate your db structure because of it's loose structure, but i'm not sure it would be intuitively clear to others. hard to say, really depends on how you implement it and how complicated your db structure is going to be.
I am aware of the batch LOAD XML technique e.g. Load XML Update Table--MySQL
Can MySql insert/replace rows directly from xml. I'd like to pass an XML string to MySQL.
Something like replace into user XML VALUES maybe even using as to map the tags to the column names??
The primary thing is that I dont want to parse the XML in my code, I'd like MySql to handle this. I dont have a file, I have the XML as a string.
I have looked and found there are some XML Functions:
12.11. XML Functions
The XML functions can do XPath, but I think this is a little fiddly as I have a 1:1 mapping from the XML to the table structure so I'd hjst like to be able to say hey MySql, insert the values in the xml string in to the table.
Is this possible?
In a nutshell, No.
What your looking for is an XML storage engine for MySQL. There has never been one created officially, and i have never seen a third party one either (but feel free to google).
If you really want to achieve this, then the closest you would get is to look for an alternative (R)DMS, but then that might not support the type of queries you wish to perform, may require a bit of a learning curve, would no doubt require you are using a server with superuser access, and potentially mean re-factoring a lot of your code.
Problem:
A Table in MySQL
that has a few normal fields and
one text field that holds XML
I need to use Solr Data Import Handler to process this table into a Solr Index.
However, the XML field needs to be parsed into several other solr fields each
Question:
Is it possible to do this without having to write a custom Transformer? If yes how. Can I use XPathEntityProcessor with a my SQL DB as datasource?
If I write a custom transformer, how exactly do I configure it in dataConfig?
I am using older version of solr (1.4.1), so can I just drop a new jar with new class into my solr web-app?
The thing I am quite unsure about is how I need to configure the data-config.xml to do this. If anyone has any examples, please share! Thanks.
My suggestion is to write a program which selects the data from the database, parses the XML data field and then inserts the entire document into the SOLR index.
The solrj Java apis are really easy to use. The hardest part of this is parsing the XML, but it's a far easier challenge and easier to test.
I need to convert an XML to a MySQL DB Schema.
I have been able to generate the XSD from the XML. Now i want to use the XSD to generate the DB schema in MySQL or PostgreSQL. Can anyone tell me how can i do this or point to any tools which i can use for this?
There is a command-line tool called XSD2DB, that generates database from xsd-files, available at sourceforge.
For more info: please refer to this existing question How can I create database tables from XSD files?
I am developing a web application right now, where the user interacts with desktop software that exports files as XML.
I was curious if there was a way to take the data from the XML file and insert that data into a mySQL database using ColdFusion?
Of course you can, ColdFusion provides powerful tools for handling XML.
Typically you'll need to parse XML file into the XML document object with XmlParse and search through it using XPath language with XmlSearch. Fetched data you can easily use for inserting into the database or any other manipulations.
Please note that there are more useful XML functions present, for example you may be interested in validation XML before parsing it.
If you'll need help for specific situations -- please extend your question or ask another one.
If you are working with XML documents that fit into memory when parsed, #Sergii's answer is the right way to go. On the other hand, XML being verbose as it is, and ColdFusion's using a DOM XML parser, can easily lead to Out of Memory errors.
In that situation, given MySQL and ColdFusion, I see two alternative paths. One is exporting the data from the desktop application as CSV, if possible. Then use MySQL's LOAD DATA INFILE, which you can call from ColdFusion to import the data. This is probably the fastest performance.
If you cannot change the desktop application's export format, consider using a Java StAX parser instead. See my answer from another question for an example of how to do this with ColdFusion. This has the advantage of only pulling in part of the XML document into memory at any given time, but is somewhat more difficult to work with than a DOM parser. As such you will not get OOM errors.
Note, there is a third type of parser available as well from Java - SAX - that has the same quality as a StAX parser of not loading the whole document into memory. However, it's a more difficult approach IMO to work with, thus the StAX recommendation.