【发布时间】:2017-01-23 08:37:40
【问题描述】:
我有一个名为 order-service-api-inbound-sample.xml
的 xml 文件谁的文件路径是 /home/bs-086/Django/mh-portal/master/portal/portal/endpoints/testdata/order-service-api-inbound-sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<purchaseOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file:/C:/Users/COMP/Desktop/purchase_order_inbound_schema.xsd">
<customer>
<customer-name>jubydull</customer-name>
<customer-address1>Bangladesh</customer-address1>
<customer-address2>dhaka</customer-address2>
<customer-city>dhaka</customer-city>
<customer-state></customer-state>
<customer-zip>1205</customer-zip>
<customer-country>Bangladesh</customer-country>
</customer>
</purchaseOrder>
我有一个名为 models.py 的模型类,其文件路径为 /home/bs-086/Django/mh-portal/master/portal/portal/endpoints/models.py
from __future__ import unicode_literals
from django.db import models
class Customer(models.Model):
name = models.CharField(max_length=120)
address1 = models.CharField(max_length=120)
address2 = models.CharField(max_length=120)
city = models.CharField(max_length=50)
state = models.CharField(max_length=50)
zip = models.IntegerField()
country = models.CharField(max_length=50)
def __str__(self):
return self.name
现在我想将 xml 文件值保存到我的模型中。我该怎么做?我正在使用 postgresql 数据库。
【问题讨论】:
-
很多不同的可能性,编写自定义反序列化器,使用 xslt 转换为标准 django 转储数据格式。将 xml 加载到 dom 中并从中创建对象。使用它的 xml 函数直接加载到 postgresql 中,....
-
给我任何资源。我是新的 Django @e4c5
标签: xml postgresql python-2.7 django-1.9