macintoshpie / bsyncpy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bsyncpy

Currently generated by BuildingSync version:

  • 2.3.0

Generating

  • poetry install
  • poetry run pre-commit install
  • Copy a version of the BuildingSync.xsd file into bsyncpy/bsync
  • cd into bsyncpy/bsync
  • Run generator: poetry run python bsyncpy_generator.py
  • Go back to bsyncpy and run tests: poetry run pytest
  • Make sure formatting is good: poetry run pre-commit run --all-files
  • On commit, pre-commit should run

Usage

Simple example

from lxml import etree
from bsync import bsync

# Create a root and set the version attribute
root = bsync.BuildingSync()
root.set('version', '2.3.0-pr1')

# Valid element attributes can also be passed in as kwargs
f = bsync.Facilities(bsync.Facilities.Facility(ID='Facility-1'))

# Add the facilities.facility elements to the root
root += f

# write the document to disk
with open('output.xml', 'wb+') as f:
    output = etree.tostring(root.toxml(), pretty_print=True, doctype='<?xml version="1.0" encoding="UTF-8"?>')
    f.write(output)

Output

<?xml version="1.0" encoding="UTF-8"?>
<BuildingSync version="2.2.0">
  <Facilities>
    <Facility ID="Facility-1"/>
  </Facilities>
</BuildingSync>

About


Languages

Language:Python 100.0%