30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
import sys, io
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
|
import xml.etree.ElementTree as ET
|
|
from backend.jrxml_reorder import normalize_jrxml
|
|
|
|
bad = '''<?xml version="1.0" encoding="UTF-8"?>
|
|
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" name="Test" pageWidth="595" pageHeight="842">
|
|
<queryString><![CDATA[SELECT 1]]></queryString>
|
|
<style name="s1"/>
|
|
<field name="f1" class="java.lang.String"/>
|
|
<property name="p1" value="v1"/>
|
|
<parameter name="param1" class="java.lang.String"/>
|
|
<title><band height="50"><textField><reportElement x="0" y="0" width="100" height="20"/></textField></band></title>
|
|
<detail><band height="30"><staticText><reportElement x="0" y="0" width="100" height="20"/><text>Hi</text></staticText></band></detail>
|
|
</jasperReport>'''
|
|
|
|
fixed = normalize_jrxml(bad)
|
|
print('=== Before ===')
|
|
root = ET.fromstring(bad)
|
|
print('Children:', [c.tag.split('}')[-1] for c in root])
|
|
|
|
print('\n=== After ===')
|
|
root2 = ET.fromstring(fixed)
|
|
print('Children:', [c.tag.split('}')[-1] for c in root2])
|
|
|
|
# 验证
|
|
import requests
|
|
r = requests.post('http://localhost:8001/validate', json={'jrxml': fixed}, timeout=10)
|
|
print(f'\nValidation: {r.json()}')
|