Xml解析问题:格式不正确(令牌无效)

时间:2015-02-16 00:03:09

标签: python xml well-formed

日志文件:

我收到以下错误消息,并且不明白如何消除它:

  

“C:\ USERNAME \ python \ lib \ xml \ sax \ handler.py”,第38行,在fatalError中   引发异常xml.sax._exceptions.SAXParseException:   \ phase_12 \ dna \ cog_hq_bossbot_sz.xml:6:64:格式不正确(无效)   令牌)

XML

<?xml version="1.0" encoding="utf-8"?>
<scene zone="10000">
    <store_suit_point id="1" type="STREET_POINT" x="18"  y="-82" z="0.025" />
    <store_suit_point id="2" type="STREET_POINT" x="62"  y="-95" z="0.025" />
    <store_suit_point id="3" type="STREET_POINT" x="112" y="-72" z="0.025" />
    <store_suit_point id="4" type="STREET_POINT" x="128" y="-23"z="0.025" />
    <store_suit_point id="5" type="STREET_POINT" x="120" y="75" z="0.025" />
    <store_suit_point id="6" type="STREET_POINT" x="-9" y="84" z="0.025" />
    <store_suit_point id="7" type="STREET_POINT" x="-7" y="23" z="0.025" />
    <store_suit_point id="8" type="STREET_POINT" x=" 106" y="11" z=" 0.025" />
    <store_suit_point id="9" type="STREET_POINT" x="80" y="-33" z="0.025" />
    <store_suit_point id="10" type="STREET_POINT"x="56" y="-5" z="0.025" />
    <store_suit_point id="11" type="STREET_POINT" x=" 14" y="2" z="0.025" />
    <store_suit_point id="12" type="STREET_POINT" x="-23" y="-56" z="0.025" />

<group name="bossbotHQ" >
    <visgroup zone= "10000" vis="10001 10002 10003 10004 10005" >
        <suit_edge a="2" b="3" />
        <suit_edge a="3" b="4" />
        <battle_cell width="20" height="20" x="40" y="-88.5" z="0" />
    </visgroup>
    <visgroup zone="10001" vis="10001 10002 10003 10004 10005">
        <suit_edge a="4" b="5" />
        <suit_edge a="5" b="6" />
        <suit_edge a="6" b="7" />

        <battle_cell width="20" height="20" x="124" y="26" z="0" />
    </visgroup>
    <visgroup zone="10002" vis="10001 10002 10003 10004 10005">
        <suit_edge a="7" b="8" />
        <suit_edge a="8" b="9" />
        <suit_edge a="9" b="10" />
        <suit_edge a="10" b="11" />     

        <battle_cell width="20" height="20" x="49.5" y="17" z="0" />
    </visgroup>

    <visgroup zone="10003" vis="10001 10002 10003 10004 10005">
        <suit_edge a="11" b="12" />
        <suit_edge a="12" b="1" />          
        <battle_cell width="20" height="20" x="-18.5" y="-27" z="0" />
    </visgroup>
    <visgroup zone="10004" vis="10001 10002 10003 10004 10005">
        <suit_edge a="1" b="2" />
        <battle_cell width="20" height="20" x="-5" y="-71" z="0" />
    </visgroup>
</group>
</scene>

解析器代码

def createSuitPlanner(self, zone):
    sp = DistributedSuitPlannerAI(self.air, zone)

与加载文件相关的另一个文件:

def setupDNA(self):
    if self.dnaStore:
        return None
    dnaFileName = self.genDNAFileName()
    self.dnaStore = simbase.air.loadDNA(dnaFileName)
    self.dnaData = self.dnaStore.generateData()
    self.initDNAInfo()
    return None
file for the loading of the dna 
def __init__(self, loader, parentFSM, doneEvent):
    CogHQExterior.CogHQExterior.__init__(self, loader, parentFSM, doneEvent)
    **dnaFile = 'phase_12/dna/cog_hq_bossbot_sz.xml'** 

2 个答案:

答案 0 :(得分:0)

不确定这些是否都是问题,但是形成良好:您的scene - 标签滞后关闭。

假设scene不是group的父级,那么XML的开头可能看起来像

<?xml version="1.0" encoding="utf-8"?>
<scene zone="10000">
    <store_suit_point id="1" type="STREET_POINT" x="18"  y="-82" z="0.025" />
    <store_suit_point id="2" type="STREET_POINT" x="62"  y="-95" z="0.025" />
    <store_suit_point id="3" type="STREET_POINT" x="112" y="-72" z="0.025" />
    <store_suit_point id="4" type="STREET_POINT" x="128" y="-23"z="0.025" />
    <store_suit_point id="5" type="STREET_POINT" x="120" y="75" z="0.025" />
    <store_suit_point id="6" type="STREET_POINT" x="-9" y="84" z="0.025" />
    <store_suit_point id="7" type="STREET_POINT" x="-7" y="23" z="0.025" />
    <store_suit_point id="8" type="STREET_POINT" x=" 106" y="11" z=" 0.025" />
    <store_suit_point id="9" type="STREET_POINT" x="80" y="-33" z="0.025" />
    <store_suit_point id="10" type="STREET_POINT"x="56" y="-5" z="0.025" />
    <store_suit_point id="11" type="STREET_POINT" x=" 14" y="2" z="0.025" />
    <store_suit_point id="12" type="STREET_POINT" x="-23" y="-56" z="0.025" />
</scene>

最后注意</scene>

答案 1 :(得分:0)

您的原始XML是well-formed。您更新的XML不是。

在以后添加的XML的scene元素中,您在store_suite_point的属性之间缺少空格:

y="-23"z="0.025"

应该是

y="-23" z="0.025"

再来一次:

type="STREET_POINT"x="56"

应该是

type="STREET_POINT" x="56" 

这些错误会导致您的XML格式不正确并且必须修复。