I’ve been doing a lot of work lately with XML data. I’m just importing from XML to MV right now but exporting MV to XML can be the same thing in reverse. Here is part 1 of a multipart discussion on the topic.
When asked “what is the most efficient way of building outbound XML docs and/or parsing/loading inbound XML docs into an MV application”, I’d say the answer depends on your experience.
If you know nothing about tools outside of MV and your only experience is with BASIC, then you can create XML as follows:
DOC= '<customers count="234">'
DOC<-1> ='<customer ID="9348939">'
DOC<-1> = ' <address>'
DOC<-1> = ' <street>1 n main</street>'
DOC<-1> = ' <city>Yourtown</city>'
DOC<-1> = ' </address>'
DOC<-1> = '</customer>' ...
That can get very tedious. These days most XML is done using tools, often free.
Personally I use .NET tools where I generate code from XSD files, the schema definitions. That often only takes a couple minutes. Then I do what is called serialization and de-serialization, which is creating XML documents using the generated code or populating variables with data from XML. This involves a one-to-one mapping of MV fields to the XML definitions. The code might look like this:
XmlCustomers xcusts = DeSerializeCustomers(); //from XML
DbmsCustomers dcusts = new DbmsCustomers();
foreach( XmlCustomer xcust in xcusts ) {
DbmsCustomer dcust = new dcust(); // create a single customer object
dcust.ID = xcust.ID;
dcust.address.street = xcust.address.street;
dcust.address.city = xcust.address.city;
dcusts.Add(dcust); // add single customer to collection of customers
}
dcusts.WriteToDbms(); write all customers to DBMS
Note from the above example that MV isn’t mentioned – the DBMS can be any MV or non-MV DBMS, or even a web service where we export the data without knowing what the DBMS or internal structures look like.
Details add to the coding time. For example, what if the customer address is not really stored in MV in the customer record even though the XML file has it all in one place. That’s not a problem. The dcust object above is just a jumping off point. When we execute WriteToDbms, the code will pull the address info into the MV files, perform validation, setup cross-references, or whatever else is required.
Other details involve data format, where you may need to convert from an external DateTime format to MV internal date format. Or there may be nested classes where you first loop on Customers, then you loop on Contacts within those customers, then you loop on phone, email and other contact details for each contact.
Generating XML is just the opposite, where we pull from MV into one or more objects, simply assign that object data into an XmlCustomer object, add XmlCustomer objects to a XmlCustomers collection, then serialize the collection to XML in one statement.
A project I’m working on now is to generate MV files and fields from XSD schema so that I can move data directly from the XML objects to the DBMS objects, and pump that directly into temporary MV files. Then someone can write BASIC code to move MV to MV without any XML involved. That BASIC code might look like this:
OPEN 'XML.CUSTOMERS' TO XCUSTS ELSE STOP
OPEN 'CUSTOMER-MASTER' TO CUSTMAST ELSE STOP
READ XREC FROM XCUSTS,NEXTID THEN
CREC = ""
CREC<1> = XREC<3>
CREC<4> = XREC<2>
CREC<21> = XREC<5> * 100
WRITE CREC ON CUSTMAST,NEXTID
END ELSE NULL
If anyone is interested in this, please let me know. I can use it for my own projects but I can see lots of applications for it.
In Part 2 I’ll discuss how XML relates to MV dictionary definitions and dynamic arrays … or rather, how it doesn’t.
In a Part 3, I may discuss XML capabilities built-in to some MV DBMS products, but articles like this require a lot more effort. I invite people familiar with each DBMS to write a guest piece here, to explain how to create and parse XML with their tools of choice. What comes to mind right now is the %XML library in Caché, and the XML API and XML/DB tools in U2.
Suggestions are welcome for other related content.
4 Responses
cfontaine
03|Aug|2009 1I’m just experiencing transfer between MV and languages like javascript, java or php and my best solution is json. You should have a look at it, it’s so simple and efficient !
Tony Gravagno
03|Aug|2009 2When you’re doing web development JSON has become a standard for transmission of complex objects. This is because a single developer generally controls both client and server, and there is no need for schema.
However when you’re exchanging data among trading partners, XML and related XSD documents are still the standard. You can also serialize documents and spreadsheets to XML as defined by schema, not JSON. And schema like DocBook are commonly used to exchange documents across the internet when people have no idea what software will be used to process it or how the data will be used. You also can’t do transformations on JSON with XSLT or parse through it with XPath or XQuery.
In short, JSON has its place, and I may blog about that too in relation to MV, but I don’t think we’re going to outgrow XML anytime in the next few decades.
dannyruckel
10|Aug|2009 3if i am working in a “D3 in *nix” environment, is .NET an option? i do like the notion of leveraging schemas to produce code. how are you mapping data elements? it seems you almost necessarily have to define dictionaries somehow to associate with a schema element.
tony, thanks for all your insights and the passion you have for the mv community. would you be averse to me nominating you for governor of MV?
danny
Tony Gravagno
10|Aug|2009 4Danny – you’re right on topic for Part 2, coming (I hope) sometime this week.
As for “running for office”, I wish this community had positions for market leaders. Sure, I’d run … whatsit pay?
Seriously, if any of these MV DBMS companies, or even Spectrum, had a position for “MultiValue Evangelist”, I’d probably apply. But they don’t – and here we are.
Leave a reply
You must be logged in to post a comment.
Search
Tony on Twitter...
Awesome! Gotta get me one tomorrow! http://t.co/xbpGrGNF INTRODUCING THE WORLD'S FIRST HOME MINI-NUCLEAR GENERATOR from @TigerDirect 2 months ago
Improve your OO coding with refactoring. Just take an hour or so to click through these tips: http://t.co/AghAGEbT 2 months ago
Fascinating blog/discussion on (C#) Enumeration classes to replace Enums, and related pros/cons: http://t.co/O2F5vh3M 2 months ago
@dwolt on snupnow: 1) create effective About page: what is it? 2) (advice given to me) get paying clients first, investors follow. 2 months ago
Archives by Tag
.NET AccuTerm AnzioWin API array avatar BASIC blog BlueFinity Caché CDP charts community correlative D3 dictionary distributed processing e-mail environment Excel Facebook file structure forum FOSS frames Google GPS graphs gravatar GUI images import/export item-id Java jBASE keys lists marketing memory mobile multivalues mv.NET mvBase MVSP mySQL NebulaXChange NebulaXLite NebulaXPlus OpenInsight OpenOffice Open Source Oracle PBX POS Postgres QM QMClient RDBMS relational SaaS SAPI savelist scanners select shell shutdown signature SMS SOA spam Spectrum speech SQL Server TAPI telephony tutorial Twilio U2 U2.NET UniObjects video Visual Studio voice Web Services wordpressCategories
Blogs
Forums
Sites
This Blog