Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Jan 15, 2014

VB Script

I've needed to access an Access file from an html file. I did could do this using VBScript. It is running very well with Internet Explorer and could be a solutions in Corporatist offices wher security level is too paranoic.

Now I'm working with vbscripts. I use it to generate local xml files. Those xml files I use  to keep data from Access files to be easier to read in my network. The answer of my small app (.hta file) is much faster then if I read straight from MS Access file.

So, I used following code to generate a new .xml file:

<script type='text/vbscript'> 
        Set oFS = CreateObject("Scripting.FileSystemObject") 
           Const strXmlFile = "Documents.xml" 
           Set objXMLFile = oFS.OpenTextFile(strXmlFile, 2, True, 0) 
            objXMLFile.WriteLine "" 
            objXMLFile.WriteLine ""'" href=""Documents.xsl""?>" 
            objXMLFile.WriteLine "
           'Set myFolder = oFS.GetFolder("Documents") 
            'For Each File In myFolder.Files 
            'FileLast = File.DateLastModified 
            'FileMod = DateDiff("d", FileLast, Now) 
            '    If FileMod < 5 Then 
             'Corporate = File.Name 
             'myDate = Split(FileLast,"/") 
             'myYear = Left(myDate(2),4) 
             'myMonth = myDate(0) 
             'myURL = "Whatever your URL is" 
             'Download = "Wherever your download site is" 
             'Call CreateXML(Corporate,myYear,myMonth,myURL,Download) 
             Call CreateXML("Corporatia","myYear","myMonth","myURL","Download") 
              
                'End If 
            'Next 
           'This next call will run once the "CreateXML" has finished. 
           Call CloseXML() 
           Function CreateXML(Corporate,myYear,myMonth,myURL,Download) 
            objXMLFile.WriteLine vbTab & "
            objXMLFile.WriteLine vbTab & vbTab & "" & Corporate & "
            objXMLFile.WriteLine vbTab & vbTab & "" & myYear & "
            objXMLFile.WriteLine vbTab & vbTab & "" & myMonth & "
            objXMLFile.WriteLine vbTab & vbTab & "" & myURL & "
            objXMLFile.WriteLine vbTab & vbTab & "" & Download & "
            objXMLFile.WriteLine vbTab & "
           End Function 
           Function CloseXML() 
            objXMLFile.WriteLine "
"              wscript.echo "Completed XML Creation" 
           End Function 

          </script>

Dec 20, 2011

Creating XML from MySQL as easy as PI


ANALYSIS
Unfortunately, importing XML into MySQL is more like chocolate cheesecake, but there are solutions available. Just follow this guide and you'll be on your way to integrating Web services with your database in no time. Starting from scratch
With the growing popularity of XML, developers have found an easy method to present data sets in a standardised way. What else does that sound like? A database! It's only natural that it should be simple to convert your information without a lot of fuss -- and you can. Some proprietary database manufacturers, such as Microsoft and IBM, have taken steps to integrate XML into their systems. This comes as no surprise since these two companies are both heavily involved in the XML standardisation project. Not wanting to be left behind, the creators of MySQL database incorporated a means for generating an XML data file. It's supported in version 3.23.48 and up. You can use the command line or facilitate the process with the programming language of your choice. To get started, you can download MySQL database  for free from MySQL.com. The current release is sufficient to support this feature, and you don't need to compile it with any special parameters. Fruit filling
Once you're installed, created, and populated your database, execute the following command to generate an XML file:
mysqldump --xml databasename [tables]
If you'd like to save this to a file, simply use the standard *NIX method of outputting to a file:
mysqldump --xml databasename > filename.xml
This produces a well formed XML document. Because XML is datacentric, if you dump your entire database and it contains no information, your file will result in a series of empty tags based on the table names. Your output should look something like this:

Now you're free to use this data file with any application you desire. This method is useful in a number of ways. Not only will it create a standardised representation of your data, but it can also take a snapshot of your database (or portion of your database) for display. Rather than making repeated calls to the database server, just generate an XML document when your database changes and reference that from Web pages or whatever you're using. This can localize calls for data, reduce the overhead of frequent calls to a database, and easily present a subset of your information for improved performance, security, or localization. Ice cream on the side
It's really easy to get XML from MySQL, but how about the other direction? That's a little trickier. MySQL itself doesn't support this function, and with good reason. The database currently has no way to validate the XML file. This could result in a number of scenarios, ranging from a partial load to ignoring malformed tags and statements to simply forcing the entire load to fail. MySQL supports only cascading back-outs in current development versions. While it's not pretty from a native standpoint, you do have some options. One solution is Perl's DBIx::XML_RDB module. You can use this method to both import and export XML, though understandably the import is heavily dependent upon a correctly structured XML file. To get the data, the module essentially runs a query and formats the results in an XML file. Conversely, you can use the module to read an XML file, create a SQL query, and execute it. There is a simpler option as well. The DBIx::XML_RDB module ships with two utility scripts to facilitate the process: xml2sql.pl and sql2xml.pl. I found agreat tutorial  on using this Perl module at O'Reilly's XML.com Web site. It will walk you through the process. Another, more generalized effort comes from Ron Bourret's XML-DBMS project . This is an ongoing effort to support XML imports and exports with relational databases using Perl and Java. There's also some very interesting work that supports mapping one database to another using XML as facilitating middleware. This is a community-oriented open source project being managed on SourceForge . Other languages, particularly Web scripting languages, haven't ignored the need to import XML into SQL databases either. There are similar efforts for Python, such as the xml2sql and dtd2sql modules, outlined in detail in this article from IBM , and a couple of projects in the works for PHP, such as the "XML MySQL class" project. Scrumptious
With these utilities, importing and exporting XML into and from MySQL is easy! Since MySQL is popular and free, it's been the test bed for integrating many scripting languages in XML, and as a result there are a number of tutorials and scripts specific for this database. With the power of a relational database and the ability to easily create XML files, MySQL can be an integral part of your Web services solution.

Nov 23, 2011

XML & PHP

The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators.



<?php
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El ActÓr</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
XML;
?>



You can find more, here: http://www.php.net/manual/en/simplexml.examples-basic.php

Aug 11, 2010

Tutorial WEBservice in PHP

In the last 2 weeks I have searched the simpliest and complete tutorial about webservices in PHP. I have founded followings:


One of the Internet's current hot topics is Web Services, introduced by Kevin Yank in his article Web Services Demystified.
If you've been following industry news on the subject, you may think this is some high level technology, of interest only to big companies with huge budgets. But if you did, you'd be wrong.
The concepts behind Web Services are remarkably simple, and in this article we'll be taking a deeper look at what's involved. Then, with a little help from our good friend PHP, we'll set up our first Web Service.
We will assume some knowledge of PHP, MySQL and XML, which -- if you're uncertain of -- you can quickly pick up from Building your own Database Driven Website using PHP & MySQLand XML - An Introduction.
So here's what's on the menu:
The Basics of Web Services: To start with we'll be quickly reviewing the basic concepts behind Web Services.
Introducing XML-RPC: Next, we'll introduce you to an XML standard for the exchange of data between systems, and we'll put it into context with Kevin's article.
PHP XML-RPC Implementations: Then we'll review some of the Open Source implementations of XML-RPC in PHP: code you can use to quickly build your own Web Service, or access other Web Services from your site.
Your first Web Service: If you want to get straight down to business, this is the place to be. Here, we'll take one of the implementations described previously, and build a Web Service for it in PHP.
What you can do with XML-RPC: Wondering what to do next? We'll give you some ideas for what you could do with XML-RPC and Web Services.
Let's get started!
The Basics of Web Services
The first thing to understand about Web Services is they're not really anything new. If you've ever used an RSS Feed to take news from another Website and place it on your own, you've already got a good idea of how Web Services work (see Kevin Yank's article: PHP and XML: Parsing RSS 1.0).
Web Services are about exchanging data between a server and a client, using a standard XML format to "package" requests and data so that both systems can "understand" each other. The server and the client could both be Web servers, or any other electronic device you care to think of.
Network-wise, data exchange in a Web Service typically happens via TCP port 80, using standard HTTP protocol POSTs. Put another way, Web Services operate in basically the same way your browser does when it POSTs an HTML form to a site, and receives a Web page in response. The only real difference is that, instead of HTML, Web Services use XML. And this means Web Services can be available anywhere on the Internet, passing through firewalls the same way viewing a Web page does. The data exchange happens at the packaging layer.
On top of the data exchange, you also need information that describes the interface (or Application Program Interface - API) to the service. This makes the Web Service useful to the rest of the Internet, allowing other developers to develop programs that can access your Web Service. This is called the description layer, and the WSDL (Web Service Description Language) standard that will make this happen is under development.
Above that, there's information that describes the nature of the service itself (not unlike the HTML-descriptive META tags), so that it can be categorised and found on sites that offer Web Service directories. This is the discovery layer, which is currently being addressed by the UDDI (Universal Description, Discovery and Integration) standard.
Both the description and discovery layers are simply XML, governed by a particular format that enables relevant information to be found for all Web Services on the Internet.
Perhaps what's made Web Services a hot topic recently -- aside from marketing by the likes of Microsoft and IBM -- is the development of these standards. They'll allow Web Services to be rolled out en masse across the Internet, backed by development tools that'll make access to them both predictable and easy.
But it should be remembered that everything a Web Service does now, in terms of data exchange, could also have been done 5 or even 10 years ago using the HTTP standard and whichever XML format you chose to use or invent (RSS feeds being a prime example). The "hot news" today is that building and distributing a Web Service is now a lot easier than in the past.
Anyway, if you're looking for a hype-free news source for the technological development in Web Services, try XML Hack.
We'll skip further generalities, but suffice it to say that this article focuses on the packaging layer, i.e. how you build and access a Web Service.