on 05-17-2013 11:32 PM
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>
Hi Pano.
I wonder if there is a problem with content in <comment> <text>.
Andreas.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.