How to generate Master/Deltail XML from maridb Rowsets ?

How to generate Master/Deltail XML from maridb Rowsets ?

Postby shri_fwh » Tue Aug 13, 2019 7:07 am

Dear Rao Sir ,

want to generate one .XML file from using Maridb Master detail rowsets , could you please share any example for the same. Thanks in advance..!

Thanks
Shridhar
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

Re: How to generate Master/Deltail XML from maridb Rowsets ?

Postby nageswaragunupudi » Tue Aug 13, 2019 7:42 am

Can you let me know how can you make xml from master-detail DBF files?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to generate Master/Deltail XML from maridb Rowsets ?

Postby shri_fwh » Tue Aug 13, 2019 8:11 am

Dear Rao Sir ,

I have never tried on XML generation in Harbour , I am seeking a function that accepts rowset and generate .XML string as similar rowset:GETROWS method which returns an array.

I have checked in the sample folder I could not find the example which generate .XML. But there are example which parse/read XML file.



Thanks
Shridhar
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

Re: How to generate Master/Deltail XML from maridb Rowsets ?

Postby cnavarro » Tue Aug 13, 2019 8:19 am

Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to generate Master/Deltail XML from maridb Rowsets ?

Postby cnavarro » Tue Aug 13, 2019 8:36 am

You have from 18.11 this functions in Fw

Before applying the class that I have suggested, you can previously use these functions to convert your obtained data to Hash or Json


* New Json (and Hash) support functions:

- ArrToHash( acHeader, aData )
Returns hHash with aHeader as keys and aData as values.
If aData is multi-dimensional array returns array of hashes
If acHeader is 2 dimensional array and aData is nil, first
dimension of acHeader is considered as head and second dimension
is considered as data.

- ArrToJson( acHeader, aData )
- RsToJson( oAdoRs, [nRows], [nStart], [aFields] ) --> Json Array
- FW_RecToJson( [acFields], [acNames] ) // for dbf record
- FW_DbfToJson( [cFieldList], [bFor], [bWhile], [nNext], [nRec], [lRest], [aData] )
- FW_DbfToHash( [cFieldList], [bFor], [bWhile], [nNext], [nRec], [lRest], [aData] )
- oMariaRs:RecToJson( [aFields] )
- oMariaRs:ToJson( [anRows], [nStart], [aFields] )


Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to generate Master/Deltail XML from maridb Rowsets ?

Postby nageswaragunupudi » Tue Aug 13, 2019 11:55 am

Rowset has the following methods:
Code: Select all  Expand view  RUN

   METHOD ToJson( anRecs, nStaPos, aFields, lwithRowNum )
   METHOD ToHash( anRecs, nStaPos, aFields, lwithRowNum )
   METHOD GetRows( anRecs, nStartPos, aFields, lwithRowNum )
 

Generate Hash or Json from the table and then Generate XML from Hash or Json using Mr. Cristobal's class.

Code: Select all  Expand view  RUN
   oCn   := FW_DemoDB()
   cJson := oCn:States:ToJson()
   oCn:Close()


Result:
Code: Select all  Expand view  RUN
[{"id":2,"CODE":"MT","NAME":"montana"},{"id":4,"CODE":"ND","NAME":"North Dakota"},{"id":5,"CODE":"SD","NAME":"South Dakota"},{"id":6,"CODE":"WY","NAME":"Wyoming"},{"id":7,"CODE":"WI","NAME":"Wisconsin A"},{"id":14,"CODE":"MA","NAME":"Massachusetts"},{"id":15,"CODE":"NE","NAME":"Nebraska hola"},{"id":16,"CODE":"NY","NAME":"New York     2"},{"id":17,"CODE":"PA","NAME":"Pennsylvania"},{"id":18,"CODE":"CT","NAME":"Connecticut"},{"id":19,"CODE":"RI","NAME":"RRRRRDIsland"},{"id":20,"CODE":"NJ","NAME":"New Jersey"},{"id":21,"CODE":"IN","NAME":"Indiana"},{"id":22,"CODE":"NV","NAME":"Nevada   xxx"},{"id":23,"CODE":"UT","NAME":"Utah"},{"id":24,"CODE":"CA","NAME":"California"},{"id":25,"CODE":"OH","NAME":"Ohio"},{"id":26,"CODE":"IL","NAME":"Illinois"},{"id":27,"CODE":"DC","NAME":"District of Columbia"},{"id":28,"CODE":"DE","NAME":"Delaware Kansas"},{"id":30,"CODE":"MD","NAME":"Maryland"},{"id":31,"CODE":"CO","NAME":"Colorado"},{"id":32,"CODE":"KY","NAME":"Kentucky"},{"id":33,"CODE":"KS","NAME":"Kansas"},{"id":34,"CODE":"VA","NAME":"Virginia"},{"id":35,"CODE":"MO","NAME":"Missouri"},{"id":36,"CODE":"AZ","NAME":"Arizona"},{"id":37,"CODE":"OK","NAME":"Oklahoma"},{"id":38,"CODE":"NC","NAME":"North Carolina"},{"id":39,"CODE":"TN","NAME":"Tennessee"},{"id":40,"CODE":"TX","NAME":"Texas"},{"id":42,"CODE":"AL","NAME":"Alabama"},{"id":43,"CODE":"MS","NAME":"Mississippi"},{"id":44,"CODE":"GA","NAME":"Georgia"},{"id":45,"CODE":"SC","NAME":"South Carolina"},{"id":46,"CODE":"AR","NAME":"Arkansas"},{"id":47,"CODE":"LA","NAME":"Louisiana"},{"id":48,"CODE":"FL","NAME":"Florida"},{"id":49,"CODE":"MI","NAME":"Michigan"},{"id":50,"CODE":"HI","NAME":"SDFS"},{"id":51,"CODE":"AK","NAME":"Alaska"},{"id":52,"CODE":"CY","NAME":"Cyprus"},{"id":53,"CODE":"10","NAME":"VILIAN ARRAES"}]


But when we talk about XML, we should also be clear about the format. Do we need field attributes (like field type, width, etc) embedded in the xml file. So, it is not as straight forward
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to generate Master/Deltail XML from maridb Rowsets ?

Postby cnavarro » Tue Aug 13, 2019 1:32 pm

Ok, with this Json of Mr Rao, please

Code: Select all  Expand view  RUN

Function Main()

   local cJson
   local hHash
   local lRepeat     := .T.      // you have "keys" repeated

   cJson := '{"states":' + cJson + "}"
   oRoot   := TXmlToHash():New( , , , lRepeat )
   ? oRoot:JsonToXml( , cJson, "myxml0.xml" )
  //oRoot:End()                        // Not use :End(), not neccesary
Return nil
 


or

Code: Select all  Expand view  RUN

Function Main()

   local cJson
   local hHash
   local lRepeat     := .T.      // you have "keys" repeated

   cJson := '{"states":' + cJson + "}"
   hb_JsonDecode( cJson, @hHash )
   oRoot   := TXmlToHash():New( , , , lRepeat )
   ? oRoot:HashToXml( hHash, "myxml1.xml" )
  //oRoot:End()                        // Not use :End(), not neccesary
Return nil
 


But, if you use METHOD End(), please modify this method
Code: Select all  Expand view  RUN

METHOD End() CLASS TXmlToHash
   if !Empty( ::oRoot )
      MxmlDelete( ::oRoot )
   endif
Return nil
 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to generate Master/Deltail XML from maridb Rowsets ?

Postby Maurizio » Tue Sep 24, 2019 7:36 am

Hello Navarro

I try XMLtoHash with some xml files does not work
this happens when the data is in the tag

<MealPlan MealPlanCode="MPT.3">

Code: Select all  Expand view  RUN
<?xml version="1.0" encoding="utf-8"?>
<OTA_HotelRatePlanRS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opentravel.org/OTA/2003/05" xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05 OTA_HotelRatePlanRS.xsd" TimeStamp="2019-09-23T15:38:16" Target="Production" Version="1.005">
  <RatePlans>
    <MealPlans>
      <MealPlan MealPlanCode="MPT.3">
        <Description>
          <Text><![CDATA[Bed & Breakfast]]></Text>
        </Description>
      </MealPlan>
      <MealPlan MealPlanCode="MPT.12">
        <Description>
          <Text><![CDATA[Half Board]]></Text>
        </Description>
      </MealPlan>
    </MealPlans>
    <RatePlan CurrencyCode="EUR" RatePlanCode="14500">
      <Rates>
        <Rate MinGuestApplicable="2" MaxGuestApplicable="2" InvTypeCode="54480" IsRoom="true" />
        <Rate MinGuestApplicable="2" MaxGuestApplicable="2" InvTypeCode="54481" IsRoom="true" />
        <Rate MinGuestApplicable="3" MaxGuestApplicable="3" InvTypeCode="54482" IsRoom="true" />
        <Rate MinGuestApplicable="3" MaxGuestApplicable="3" InvTypeCode="54483" IsRoom="true" />
        <Rate MinGuestApplicable="4" MaxGuestApplicable="4" InvTypeCode="54484" IsRoom="true" />
      </Rates>
      <Description>
        <Text><![CDATA[Web Rate]]></Text>
      </Description>
    </RatePlan>
    <RatePlan CurrencyCode="EUR" RatePlanCode="14501">
      <Rates>
        <Rate MinGuestApplicable="2" MaxGuestApplicable="2" InvTypeCode="54480" IsRoom="true" />
        <Rate MinGuestApplicable="2" MaxGuestApplicable="2" InvTypeCode="54481" IsRoom="true" />
        <Rate MinGuestApplicable="3" MaxGuestApplicable="3" InvTypeCode="54482" IsRoom="true" />
        <Rate MinGuestApplicable="3" MaxGuestApplicable="3" InvTypeCode="54483" IsRoom="true" />
        <Rate MinGuestApplicable="4" MaxGuestApplicable="4" InvTypeCode="54484" IsRoom="true" />
      </Rates>
      <Description>
        <Text><![CDATA[Not Refundable]]></Text>
      </Description>
    </RatePlan>
  </RatePlans>
</OTA_HotelRatePlanRS>


Regards Maurizio
User avatar
Maurizio
 
Posts: 825
Joined: Mon Oct 10, 2005 1:29 pm

Re: How to generate Master/Deltail XML from maridb Rowsets ?

Postby cnavarro » Tue Sep 24, 2019 7:41 am

Dear Maurizio, what do you want to do with this xml?
Please enter your code
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to generate Master/Deltail XML from maridb Rowsets ?

Postby Maurizio » Tue Sep 24, 2019 12:38 pm

Navarro ,
I have already manually encoded the XML file.
This is a test of your XMLtoHash function to see if the generated hash matches with the XML file.
In the generated HASH there are no tags like
<MealPlan MealPlanCode = "MPT.3">

Maurizio
User avatar
Maurizio
 
Posts: 825
Joined: Mon Oct 10, 2005 1:29 pm

Re: How to generate Master/Deltail XML from maridb Rowsets ?

Postby cnavarro » Tue Sep 24, 2019 9:26 pm

Maurizio wrote:Navarro ,
I have already manually encoded the XML file.
This is a test of your XMLtoHash function to see if the generated hash matches with the XML file.
In the generated HASH there are no tags like
<MealPlan MealPlanCode = "MPT.3">

Maurizio


Maurizio, I found this:
Code: Select all  Expand view  RUN

      ::oRoot      := MxmlLoadString( NIL, cXml, @uType_Callback() )
 


return error in line

<![CDATA[Bed & Breakfast]]>

if you delete "&" char, it run
I look this, but is a problem of function of library
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests