FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to generate Master/Deltail XML from maridb Rowsets ?
Posts: 336
Joined: Mon Dec 07, 2009 02:49 PM
How to generate Master/Deltail XML from maridb Rowsets ?
Posted: Tue Aug 13, 2019 07: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 24.04, BCC 7 32 bit, MariaDB
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to generate Master/Deltail XML from maridb Rowsets ?
Posted: Tue Aug 13, 2019 07:42 AM

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

Regards



G. N. Rao.

Hyderabad, India
Posts: 336
Joined: Mon Dec 07, 2009 02:49 PM
Re: How to generate Master/Deltail XML from maridb Rowsets ?
Posted: Tue Aug 13, 2019 08: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 24.04, BCC 7 32 bit, MariaDB
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to generate Master/Deltail XML from maridb Rowsets ?
Posted: Tue Aug 13, 2019 08: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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to generate Master/Deltail XML from maridb Rowsets ?
Posted: Tue Aug 13, 2019 08: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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to generate Master/Deltail XML from maridb Rowsets ?
Posted: Tue Aug 13, 2019 11:55 AM
Rowset has the following methods:
Code (fw): Select all Collapse
聽 聽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 (fw): Select all Collapse
聽 聽oCn 聽 := FW_DemoDB()
聽 聽cJson := oCn:States:ToJson()
聽 聽oCn:Close()


Result:
Code (fw): Select all Collapse
[{"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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to generate Master/Deltail XML from maridb Rowsets ?
Posted: Tue Aug 13, 2019 01:32 PM
Ok, with this Json of Mr Rao, please

Code (fw): Select all Collapse
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 (fw): Select all Collapse
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 (fw): Select all Collapse
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
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: How to generate Master/Deltail XML from maridb Rowsets ?
Posted: Tue Sep 24, 2019 07: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 (fw): Select all Collapse
<?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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to generate Master/Deltail XML from maridb Rowsets ?
Posted: Tue Sep 24, 2019 07: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
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: How to generate Master/Deltail XML from maridb Rowsets ?
Posted: 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

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to generate Master/Deltail XML from maridb Rowsets ?
Posted: Tue Sep 24, 2019 09: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 (fw): Select all Collapse
      ::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

Continue the discussion