File: xml_example.py

package info (click to toggle)
swi-prolog 9.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 82,408 kB
  • sloc: ansic: 387,503; perl: 359,326; cpp: 6,613; lisp: 6,247; java: 5,540; sh: 3,147; javascript: 2,668; python: 1,900; ruby: 1,594; yacc: 845; makefile: 428; xml: 317; sed: 12; sql: 6
file content (43 lines) | stat: -rw-r--r-- 1,551 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Example of creating the wire format in 'Example: A Simple XML Like Structure'"""

import pb_vector_pb2 as xpb


def main():
    xml = xpb.XMLFile(elements=[
        xpb.xml_element(
            name="space1",
            attributes=[
                xpb.kv_pair(key="foo", atom_value="1"),
                xpb.kv_pair(key="bar", atom_value="2")
            ],
            contents=[
                xpb.aux_xml_element(atom="fum"),
                xpb.aux_xml_element(atom="bar"),
                xpb.aux_xml_element(
                    element=xpb.xml_element(
                        name="space2",
                        attributes=[
                            xpb.kv_pair(key="fum", float_value=3.1415),
                            xpb.kv_pair(key="bum", int_value=-14)
                        ],
                        contents=[xpb.aux_xml_element(atom="more stuff for you")])),
                xpb.aux_xml_element(
                    element=xpb.xml_element(
                        name="space2b",
                        contents=[
                            xpb.aux_xml_element(atom="this"),
                            xpb.aux_xml_element(atom="is"),
                            xpb.aux_xml_element(atom="embedded"),
                            xpb.aux_xml_element(atom="also")
                        ])),
                xpb.aux_xml_element(atom="to"),
                xpb.aux_xml_element(atom="you")
            ])
    ])
    # print('xml:', xml)
    print(list(xml.SerializeToString()))


if __name__ == "__main__":
    main()