Tarek
Tarek

Reputation: 31

PBDOM : Exporting to XML file gives a single line

I've been starting developing with PowerBuilder 12.5 a few weeks ago. I had to write some XML files, so I got familiar with the PBDOM library.

I can build a lot of different things, it's very nice, but one thing still bothers me :
In the output file, the whole XML is written on a single line.

I use the SaveDocument function.

For example, here is some code :

PBDOM_Document              doc
PBDOM_Element               noderoot, node1, node11, node12

doc = CREATE PBDOM_Document
doc.NewDocument("NodeRoot")
noderoot = doc.GetRootElement()

node1 = CREATE PBDOM_Element
node1.SetName("Node1")
noderoot.AddContent(node1)
node1.SetAttribute("Attr", "AttrValue")

node11 = CREATE PBDOM_Element
node11.SetName("Node11")
node11.AddContent("Here is a value")
node1.AddContent(node11)

node12 = CREATE PBDOM_ELEMENT
node12.SetName("Node12")
node12.AddContent("Here is another value")
node1.AddContent(node12)

doc.SaveDocument("myDoc.xml")

Here is the result when I open it with notepad++

<NodeRoot><Node1 Attr="AttrValue"><Node11>Here is a value</Node11><Node12>Here is another value</Node12></Node1></NodeRoot>

Whereas I wanted :

<NodeRoot>
    <Node1 Attr="AttrValue">
        <Node11>Here is a value</Node11>
        <Node12>Here is another value</Node12>
    </Node1>
</NodeRoot>

With the notepad++ XML tools plugin, I can use the "pretty print" function to get this nice representation. But I would like my file to be formatted this way from the beginning. I noticed that the "line ending" was set to UNIX format (indicator on bottom right of the window), but I'm working on Windows. When I use the menu to convert it to Windows format (CR+LF), it changes this indicator, but the code stays on one single line.

Is there a way to tell PBDOM to export the XML file with a nice output ?

Thank you !

Notes :
- Opening the XML file with Internet Explorer or Google Chrome gives me a nice vizualisation, with indentation, line breaks...
- Adding a <?xml version="1.0" encoding="ISO-8859-1" ?> does not help (I've been doing it while exporting some more complex files, but I still get the output on one line...)

Upvotes: 0

Views: 1681

Answers (1)

Jagannath
Jagannath

Reputation: 41

Instead of using pbdom to write the xml document, you can do as below if possible:

  1. Create a datawindow object with necessary fields.
  2. Design the xml template inside datawindow design view.
  3. Important: in the export property tab of datawindow there is one option called "Include White Space", check it.
  4. At run time populate data in the datawindow/datastore.
  5. Do a saveas of the datawindow/datastore with saveas type xml.

Now you will have a xml document that is well formatted. It's very easy also.

see if this helps.

Upvotes: 1

Related Questions