cancel
Showing results for 
Search instead for 
Did you mean: 

PBDOM - A little help

Former Member
0 Kudos

I am reverting my XML parsings from Visual Studio to PB 11.5.1

I have some quite huge XMLs and I trying to understand how PBDOM works (and have very little time to do so ).

Below is a tiny bit of an XML that I need to parse.

Could you provide my some sample code (just the beginning of a parse into variables) in order to understand practically PBDOM's philosophy?

Thanx in advance!

<RoomStays>

          <RoomStay>

                    <RoomRates>

                              <RoomRate NumberOfUnits="1" RatePlanCode="XXX1" RoomTypeCode="YYY2">

                                        <Rates>

                                                  <Rate EffectiveDate="2013-05-22" ExpireDate="2013-05-23" RateTimeUnit="Day" UnitMultiplier="1">

                                                            <Base AmountAfterTax="140.00" CurrencyCode="USD"/>

                                                  </Rate>

                                                  <Rate EffectiveDate="2013-05-23" ExpireDate="2013-05-24" RateTimeUnit="Day" UnitMultiplier="1">

                                                            <Base AmountAfterTax="120.00" CurrencyCode="USD"/>

                                                  </Rate>

                                        </Rates>

                              </RoomRate>

                    </RoomRates>

                    <GuestCounts>

                              <GuestCount Age="1" Count="1"/>

                    </GuestCounts>

                    <TimeSpan End="2013-05-24" Start="2013-05-22"/>

                    <Total AmountAfterTax="280.00" CurrencyCode="USD"/>

                    <BasicPropertyInfo CompanyCode="XXX"/>

                    <Comments>

                              <Comment>

                                        <Text>This is a test comment !@ $%^&*()123</Text>

                              </Comment>

                    </Comments>

          </RoomStay>

</RoomStays>

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Pano.

I wonder if there is a problem with content in <comment> <text>.

Andreas.

Former Member
0 Kudos

No,just random chars Andrea

former_member190719
Active Contributor
0 Kudos

Actually, Andreas is correct.  You've got a "&" character in that comment, which is a reserved character in XML.  That needs to be encoded correctly or the XML document will not be valid.

former_member190719
Active Contributor
0 Kudos

Once you've corrected the reserved character, you could use something like the following to parse the document:

pbdom_builder          builder    

pbdom_document     document

pbdom_element      root

pbdom_element      ldom_childelements[]

pbdom_attribute     ldom_effdate

pbdom_attribute     ldom_expdate

pbdom_attribute     ldom_aftertax

pbdom_attribute     ldom_currency

pbdom_element          base

integer                    li_count, li_index

string                         ls_message

builder = CREATE PBDOM_BUILDER

try

 

     //Create a DOM document from the XML file

     document = builder.BuildFromFile ( "document.xml" )

    

     //Get a handle to the root element

     root = document.GetRootElement()

      document.GetElementsByTagName ( "Rate", ldom_childelements[] )

    

     li_count = UpperBound ( ldom_childelements[] )

     FOR li_index = 1 TO li_count

          ldom_effdate = ldom_childelements[li_index].getattribute( "EffectiveDate" )

          ldom_expdate = ldom_childelements[li_index].getattribute( "ExpireDate" )

          base = ldom_childelements[li_index].getchildelement( "Base" )

          ldom_aftertax = base.getattribute( "AmountAfterTax" )

          ldom_currency = base.getattribute( "CurrencyCode" )

          ls_message += "From " + ldom_effdate.gettext( ) + " to " + ldom_expdate.gettext() + " the rate is " + ldom_aftertax.gettext() + " " + ldom_currency.gettext() + "~r~n"

     NEXT

    

     MessageBox ( "Rates", ls_message )

    

catch ( PBDOM_Exception except )

     MessageBox ("Exception Occurred", except.Text )

finally

     Destroy builder

end try

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

Check out my article in PBDJ "Taking PowerBuilder's PBDOM Out for a Spin" http://pbdj.sys-con.com/node/107057 Its quite old but should cover the basics.

Regards

Arthur