예제 #1
0
 def write(cls, output: TextIO, obj: "GeneratorConfig"):
     ctx = XmlContext(
         element_name_generator=text.pascal_case,
         attribute_name_generator=text.camel_case,
     )
     config = SerializerConfig(pretty_print=True)
     serializer = XmlSerializer(context=ctx,
                                config=config,
                                writer=XmlEventWriter)
     serializer.write(output,
                      obj,
                      ns_map={None: "http://pypi.org/project/xsdata"})
예제 #2
0
def write_file_from_xml(xml_file_path: pathlib.Path,
                        serialize_clazz: Optional[Type[T]]):
    """
    Method to write serialized XML data to a file.
    :param xml_file_path: A pathlib.path path object that the data will write to.
    :param serialize_clazz: A class Object.
    :return: N/A
    """
    serializer = XmlSerializer(
        config=SerializerConfig(pretty_print=True,
                                encoding="UTF-8",
                                xml_version="1.1",
                                xml_declaration=False,
                                schema_location="resources/xmltv.xsd",
                                no_namespace_schema_location=None))

    with xml_file_path.open("w") as data:
        serializer.write(data, serialize_clazz)
예제 #3
0
def write(size, obj, writer):
    with xsdata_temp_dir.joinpath(f"benchmark_{size}.xml").open("w") as f:
        serializer = XmlSerializer(writer=writer, context=context)
        serializer.write(f, obj)
예제 #4
0
import sys
from pathlib import Path

from xsdata.formats.dataclass.parsers import XmlParser
from xsdata.formats.dataclass.serializers import XmlSerializer
from xsdata.formats.dataclass.serializers.config import SerializerConfig

from reqif.models import ReqIf

here = Path(__file__).parent

xml_fixture = here.joinpath("sample.xml")
parser = XmlParser()
config = SerializerConfig(pretty_print=True, encoding="ascii")
serializer = XmlSerializer(context=parser.context, config=config)

obj = parser.from_path(xml_fixture, ReqIf)
ns_map = {
    None: "http://www.omg.org/spec/ReqIF/20110401/reqif.xsd",
    "xhtml": "http://www.w3.org/1999/xhtml",
}
serializer.write(sys.stdout, obj, ns_map=ns_map)