Pythonコードとして出力するPython &で解析しているXMLファイルがあります。PythonでXMLを解析する際に特殊文字を保持していますか?
一部のXMLにはReg Ex値と文字列が含まれています。この値は画面上にダイアログとして表示されるため、維持する必要がある特殊文字がいくつかあります。コードは次のとおりですが、どのようにこれを行うことができますか?
XMLはこのように少し見えます。
<variable id="passportnumber" value="" type="String">
<validate>
<regularExpression fieldID="passportnumber" errorID="3007162"><![CDATA[^[a-zA-Z+:?<>;*()%="!0-9./',&\s-]{1,35}$]]></regularExpression>
</validate>
</variable>
ダイアログの場合。
<if>
<condition><![CDATA[$taxcode$ == $previousemergencytaxcode$ and $previousemergencytaxcode$ != $emergencytaxcode$]]></condition>
<then>
<dialog id="taxCodeOutdatedDialog" text="Are you sure this is the correct tax
code? The emergency code for the tax year 2011-12 was
'$previousemergencytaxcode$'. The emergency code for the tax
year 2012-13 is '$emergencytaxcode$'. Proceed?" type="YES|NO|CANCEL" />
</then>
</if>
フルPythonスクリプトはhereで、具体的には、これらの二つである解析します。
def parse_regularExpression(self, elem):
self.out('')
self.out("item_regularExpression(fieldID='{0}', value='{1}')".format(elem.attrib['fieldID'],elem.text))
def parse_dialog(self, elem):
self.out('')
self.out("item_dialog(id='{0}', text='{1}', type='{2}')".format(elem.attrib['id'], elem.attrib['text'],elem.attrib['type']))
ラインフィード(
)は、私が対処する方法がわからないんだ主なものです。それは、たとえそれが三重引用符であっても、改行としてそれを出力しているようです。テキスト値を次のように出力します。
item_dialog(id='taxCodeOutdatedDialog', text='Are you sure this is the correct tax code?
The emergency code for the tax year 2011-12 was '$previousemergencytaxcode$'.
The emergency code for the tax year 2012-13 is '$emergencytaxcode$'.
Proceed?', type='YES|NO|CANCEL')
はい!時には私はあまりにも多くの考えを与えたときに明白なことを指摘する必要があります!ありがとう。ちょうど今すぐ値をサブする正規表現を把握する必要があります:) –