0
Votes
Undo
  1. Malek Taha
  2. PowerBuilder
  3. Tuesday, 15 August 2023 22:24 PM UTC

Hi

    This is my first time working with XML and i want to use the PDOM to build the document.

I have this xml exported from a datawindow

<?xml version="1.0" ?>
<Phonebook>
<Family>
<Malek>
<Name>Malek Taha</Name>
<PhoneNumber>1112223333</PhoneNumber>
<Address>
<AddressLine1>1 Main Street </AddressLine1>
<AddressLine2 />
<AddressLine3 />
<City>Detroit</City>
<StateProvinceCode>MI</StateProvinceCode>
<PostalCode>11222</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</Malek>
<Lisa>
<Name>Lisa Doe</Name>
<PhoneNumber>1112223333</PhoneNumber>
<Address>
<AddressLine1>2 Main Street </AddressLine1>
<AddressLine2 />
<AddressLine3 />
<City>Detroit</City>
<StateProvinceCode>MI</StateProvinceCode>
<PostalCode>11222</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</Lisa>

<Tina>
<Name>Tina Doe</Name>
<PhoneNumber>1112223333</PhoneNumber>
<Address>
<AddressLine1>3 Main Street </AddressLine1>
<AddressLine2 />
<AddressLine3 />
<City>Detroit</City>
<StateProvinceCode>MI</StateProvinceCode>
<PostalCode>11222</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</Tina>
</Family>
</Phonebook>

 

I want to add this document in the above document after the <Lisa> eliment.

<Mary>
<Name>Mary Doe</Name>
<PhoneNumber>1112223333</PhoneNumber>
<Address>
<AddressLine1>4 Main Street </AddressLine1>
<AddressLine2 />
<AddressLine3 />
<City>Detroit</City>
<StateProvinceCode>MI</StateProvinceCode>
<PostalCode>11222</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</Mary>

 

Pleaase help

Thanks

Malek

 

René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 16 August 2023 05:53 AM UTC
  2. PowerBuilder
  3. # 1

Here a short example:

 

string ls_xml, ls_new
pbdom_builder pbdom_builder_1
pbdom_document pbdom_doc, pbdom_doc2
pbdom_element pbdom_elem_mary, pbdom_elem_family, pbdom_elem_tina
pbdom_element pbdom_elem_root

ls_xml = '<?xml version="1.0" ?> &
<Phonebook> &
<Family> &
<Malek> &
<Name>Malek Taha</Name> &
<PhoneNumber>1112223333</PhoneNumber> &
<Address> &
<AddressLine1>1 Main Street </AddressLine1> &
<AddressLine2 /> &
<AddressLine3 /> &
<City>Detroit</City> &
<StateProvinceCode>MI</StateProvinceCode> &
<PostalCode>11222</PostalCode> &
<CountryCode>US</CountryCode> &
</Address> &
</Malek> &
<Lisa> &
<Name>Lisa Doe</Name> &
<PhoneNumber>1112223333</PhoneNumber> &
<Address> &
<AddressLine1>2 Main Street </AddressLine1> &
<AddressLine2 /> &
<AddressLine3 /> &
<City>Detroit</City> &
<StateProvinceCode>MI</StateProvinceCode> &
<PostalCode>11222</PostalCode> &
<CountryCode>US</CountryCode> &
</Address> &
</Lisa> &
<Tina> &
<Name>Tina Doe</Name> &
<PhoneNumber>1112223333</PhoneNumber> &
<Address> &
<AddressLine1>3 Main Street </AddressLine1> &
<AddressLine2 /> &
<AddressLine3 /> &
<City>Detroit</City> &
<StateProvinceCode>MI</StateProvinceCode> &
<PostalCode>11222</PostalCode> &
<CountryCode>US</CountryCode> &
</Address> &
</Tina> &
</Family> &
</Phonebook>'

ls_new = '<Mary> &
<Name>Mary Doe</Name> &
<PhoneNumber>1112223333</PhoneNumber> &
<Address> &
<AddressLine1>4 Main Street </AddressLine1> &
<AddressLine2 /> &
<AddressLine3 /> &
<City>Detroit</City> &
<StateProvinceCode>MI</StateProvinceCode> &
<PostalCode>11222</PostalCode> &
<CountryCode>US</CountryCode> &
</Address> &
</Mary>'


pbdom_builder_1 = Create PBDOM_Builder

pbdom_doc = pbdom_builder_1.BuildFromString (ls_xml)
pbdom_doc2 = pbdom_builder_1.BuildFromString (ls_new)

pbdom_elem_mary = pbdom_doc2.GetRootElement()
pbdom_elem_mary.Detach()

pbdom_elem_root = pbdom_doc.GetRootElement()
pbdom_elem_family = pbdom_elem_root.getchildelement ("Family")
pbdom_elem_tina = pbdom_elem_family.getchildelement ("Tina")

pbdom_elem_family.InsertContent(pbdom_elem_mary, pbdom_elem_tina)

ls_xml = pbdom_doc.savedocumentintostring()
MessageBox ("", ls_xml)

 

Comment
There are no comments made yet.
Malek Taha Accepted Answer Pending Moderation
  1. Tuesday, 22 August 2023 23:09 PM UTC
  2. PowerBuilder
  3. # 2

Thanks Rene

       Thanks for the reply. It was very very helpful and i was able to b uild my xml nicely using your example.

It was clear and better than any documentation i could find. easy to understand and follow.

 

That said i have a small issue still 

I sent the xml and got a response back 

see below

Now i want to get the value of the element <ShipmentIdentificationNumber>

 equal to 1ZXXXXXXXXXXXXXXXX

Can you please advise

Thanks

Malek

 

example

<?xml version="1.0"?>
<Shipment>
<Response>
<ResponseStatusCode>1</ResponseStatusCode>
<ResponseStatusDescription>Success</ResponseStatusDescription>
<Error>
<ErrorSeverity>Warning</ErrorSeverity>
<ErrorCode>129001</ErrorCode>
<ErrorDescription>Additional Handling has automatically been set on Package 1.</ErrorDescription>
</Error>
</Response>
<ShipmentCharges>
<ServiceOptionsCharges>
<CurrencyCode>USD</CurrencyCode>
<MonetaryValue>0.00</MonetaryValue>
</ServiceOptionsCharges>
</ShipmentCharges>
<ShipmentIdentificationNumber>1ZXXXXXXXXXXXXXXXX</ShipmentIdentificationNumber>
</Shipment>

 

 

Comment
  1. René Ullrich
  2. Wednesday, 23 August 2023 06:16 AM UTC
Start with GetRootElement() to get the <Shipment> node. From this node object you can call GetChildElement("ShipmentIdentificationNumber") to get the node object with the number you want. To get its valuie you can call the GetText() function for this node object.
  1. Helpful 3
There are no comments made yet.
Malek Taha Accepted Answer Pending Moderation
  1. Friday, 15 September 2023 21:06 PM UTC
  2. PowerBuilder
  3. # 3

Thank You

This was so helpful it worked and i learned a few things from it,

 

Thanks

Appreciated

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.