xmlstarlet用于获取和解析标记之间的数据

时间:2018-01-08 04:36:38

标签: xmlstarlet

我希望从xml标记获取数据到脚本文件,但数据是十六进制字符行(& >),需要转换为表格(&&>) 。

示例:

<project>
<code><shell> if a &amp;&amp; b </shell></code>
</project>

我可以使用命令

提取标签
xmlstarlet edit --update 'project/code/shell' --value "$DATA" shell.xml > shell.sh

cat shell.sh

实际值:

if a &amp;&amp; b

预期:

if a && b

如何实现预期结果?

1 个答案:

答案 0 :(得分:1)

要取消特殊的XML字符:

 if a && b 

输出:

cat file.xml | xmlstarlet unescape
<project>
<code><shell> if a && b </shell></code>
</project>

输出:

def save_report(request):
    if request.method == 'POST':
        print(request.POST.dict())
        data_dict = request.POST.dict()
        query_json = {}
        #query json data
        query_json['data_src_name'] = data_dict['data_src_name']
        query_json['fields']        = data_dict['fields']
        query_json['group_by']      = data_dict['group_by']
        query_json['order_by']      = data_dict['order_by']
        query_json['where']         = data_dict['where']
        query_json['limit']         = data_dict['limit']
        query_json                  = json.dumps(query_json)
        report_creation_obj = ReportCreationData.objects.create(
                            query_json       = query_json, 
                            data_source_name = data_dict['data_src_name'], 
                            query_name       = data_dict['query_name'], 
                            mail_body        = data_dict['mail_body'])

        report_creation_obj.save()

        return HttpResponse('success')

    else:
        return render(request, 'home/report_creation.html', context = None)

database :

query_name = models.CharField(max_length=100,unique= True, default= True)