如何将Python中的初始化对象序列化为XML?

2024-10-02 22:36:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python还很陌生。我现在学习如何在Java中对对象进行封送/解封。 我正在寻找类似Java的东西。 比如:

JAXBContext jaxbContext = JAXBContext.newInstance(com.Request1.class);
                Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                dbf.setNamespaceAware(true);
                DocumentBuilder db = dbf.newDocumentBuilder();
                Document doc = db.parse(new InputSource(new StringReader(message)));

                requestStr2 = (com.Request1) unmarshaller.unmarshal(doc);

其中Request1具有@XmlRootElement注释

我不想写多个元素、子元素等,因为我有非常复杂的xsd结构。我想通过generateDS从xsd生成类,然后从数据库初始化它并序列化为xml文件

我看过pyxser,但它只在Python2上出现。 什么模块可以帮我? 多谢各位


Tags: com元素newdbdocjavaxsddbf