41 lines
872 B
Python
41 lines
872 B
Python
from ..generated.alpinebits import OtaPingRq, OtaPingRs
|
|
from xsdata_pydantic.bindings import XmlParser
|
|
|
|
|
|
|
|
|
|
def main():
|
|
# test parsing a ping request sample
|
|
|
|
path = "AlpineBits-HotelData-2024-10/files/samples/Handshake/Handshake-OTA_PingRQ.xml"
|
|
|
|
with open(
|
|
path, "r", encoding="utf-8") as f:
|
|
xml = f.read()
|
|
|
|
# Parse the XML into the request object
|
|
|
|
# Test parsing back
|
|
|
|
|
|
parser = XmlParser()
|
|
|
|
|
|
|
|
parsed_result = parser.from_string(xml, OtaPingRq)
|
|
|
|
print(parsed_result.echo_data)
|
|
|
|
# save json in echo_data to file with indents
|
|
output_path = "parsed_echo_data.json"
|
|
with open(output_path, "w", encoding="utf-8") as out_f:
|
|
import json
|
|
json.dump(json.loads(parsed_result.echo_data), out_f, indent=4)
|
|
print(f"Saved echo_data json to {output_path}")
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
main() |