1. TOMAZ KRALJ
  2. PowerBuilder
  3. Monday, 11 January 2021 14:20 PM UTC

Hi guys!

I have PB 2019 R2 and for the first time I have to create XML document with PBDOM.

So at  the beginning of new xml file I have to write Processing instruction:

<? xml version="1.0" encoding="utf-8" standalone="yes"?> 


My sample code:

PBDOM_PROCESSINGINSTRUCTION pbdom_proc
PBDOM_DOCUMENT pbdom_dokument
PBDOM_ELEMENT pbdom_elem_root,pbdom_acc_header
PBDOM_ELEMENT pbdom_orgid
PBDOM_ATTRIBUTE pbdom_attr
PBDOM_TEXT pbdom_txt

pbdom_dokument = Create PBDOM_DOCUMENT

pbdom_dokument.NewDocument("Accounting")

pbdom_elem_root = pbdom_dokument.GetRootElement()

 

pbdom_acc_header = Create PBDOM_ELEMENT
pbdom_orgid= Create PBDOM_ELEMENT

pbdom_acc_header.setname("AccontingHeader")


pbdom_orgid.setname("OrganizationId_DK")
pbdom_orgid.AddContent("2")

pbdom_elem_root.AddContent(pbdom_acc_header) 

pbdom_acc_header.AddContent(pbdom_orgid)

pbdom_dokument.savedocument("c:\test.xml")

 

/////////////////////

How and where to code Processing instructions that will be at the beginning of xml file? Could someone show me?

Thanks and stay healthy!

Tomaz 

 

 

 

 

 

Accepted Answer
Daryl Foster Accepted Answer Pending Moderation
  1. Monday, 11 January 2021 23:49 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Tomaz,

You need to create the processing instruction, name it, add the data and then add it to the document.  If you add these lines before saving the document it should work:

pbdom_proc = create PBDOM_PROCESSINGINSTRUCTION
pbdom_proc.SetName("xml")
pbdom_proc.SetData('version="1.0" encoding="utf-8" standalone="yes"')
pbdom_dokument.AddContent(pbdom_proc)

Comment
  1. TOMAZ KRALJ
  2. Tuesday, 12 January 2021 06:17 AM UTC
Thank you Daryl,



that was solution I was looking for!



I got impression that not many PB developer use PBDOM for xml processing? Do you all use Datawindows xml templates?



I am missing some good example of using PBDOM in PB documentation, and also in PB Example App.



Regards

Tomaz
  1. Helpful
  1. Daryl Foster
  2. Tuesday, 12 January 2021 07:02 AM UTC
Hi Tomaz, I haven't really used xml for about 10 years, the last time was in Powerbuilder 10.5. Most of my current work is using JSON. When I did use xml, I mainly used the Datawindow xml templates for creating xml. It was pretty good once I worked out what I was doing. From memory you can use nested reports to create nested xml from a data window.



I also used PBDOM occasionally for modifying (or combining) the xml generated from the Datawindow template xml.



My main use of PBDOM was for parsing existing xml for processing rather than for creating xml. It is quite powerful once you get the hang of it.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Monday, 11 January 2021 20:23 PM UTC
  2. PowerBuilder
  3. # 1

Greetings, Tomaz - 

See if the SetData method of the PBDOM_PROCESSINGINSTRUCTION class does what you are looking for.

The URL Govinda provided did not work for me. Try the following if you have trouble:

https://docs.appeon.com/pb2019r2/extension_reference/ch16s01.html

Regards, John

Comment
There are no comments made yet.
Govinda Lopez @Appeon Accepted Answer Pending Moderation
  1. Monday, 11 January 2021 17:07 PM UTC
  2. PowerBuilder
  3. # 2

Hi Tomaz,

 

You may find a Code Sample from the CodeXchange here: https://community.appeon.com/index.php/codeexchange/powerbuilder/55-pbdom-xml-recursion-parse-to-treeview#52 

 

This might help you better understand what you are looking for.

 

 

Regards,

Comment
  1. TOMAZ KRALJ
  2. Monday, 11 January 2021 17:30 PM UTC
Hi Govinda,

Sample which you sent to me doesn't describe problem I have. In general I understand XML.

I have problems creating new XML with PBDOM, especially with PBBOM_PROCESSINGINSTRUCTION class.

I don't know how to incorporate in xml documents.



Regards

Tomaz
  1. Helpful
  1. Govinda Lopez @Appeon
  2. Monday, 11 January 2021 19:14 PM UTC
You may find detailed documentation about this class here: https://www.appeon.com/system/files/product-manual/extension_reference_2019R2.pdf



If I find a code sample using this class I'll share it to you through here.
  1. Helpful
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.