У меня есть файл XML, который выглядит следующим образом:Замена уникальных идентификаторов в файле
<species compartment="compartment" id="alpha_dash_D_dash_glucose_dash_6P" initialAmount="0" hasOnlySubstanceUnits="true" constant="false" boundaryCondition="false">
</species>
<species compartment="compartment" id="six_dash_Phospho_dash_D_dash_gluconate" initialAmount="0" hasOnlySubstanceUnits="true" constant="false" boundaryCondition="false">
</species>
<species compartment="compartment" id="beta_dash_D_dash_Fructose_dash_6P2" initialAmount="0" hasOnlySubstanceUnits="true" constant="false" boundaryCondition="false">
</species>
<species compartment="compartment" id="beta_dash_D_dash_Glucose" initialAmount="0" hasOnlySubstanceUnits="true" constant="false" boundaryCondition="false">
</species>
каждый id
атрибут Я хочу, чтобы заменить мой собственный атрибут. Я хочу, чтобы мой конец файла, чтобы выглядеть следующим образом:
<species compartment="compartment" id="id1" initialAmount="0" hasOnlySubstanceUnits="true" constant="false" boundaryCondition="false">
</species>
<species compartment="compartment" id="id2" initialAmount="0" hasOnlySubstanceUnits="true" constant="false" boundaryCondition="false">
</species>
<species compartment="compartment" id="id3" initialAmount="0" hasOnlySubstanceUnits="true" constant="false" boundaryCondition="false">
</species>
<species compartment="compartment" id="id4" initialAmount="0" hasOnlySubstanceUnits="true" constant="false" boundaryCondition="false">
Однако ссылается атрибут id
в других местах в файле:
<speciesReference constant="true" stoichiometry="1" species="alpha_dash_D_dash_glucose_dash_6P">
эта линия должна быть обновлена:
<speciesReference constant="true" stoichiometry="1" species="id1">
Я пробовал использовать sed
с 's/id="(*)"/id="$IdCOUNTER"/g'
, но это делает все id
атрибутами же. Как я могу это решить? Любая помощь приветствуется, спасибо.
thanks @traybold, я собирался использовать XML-парсер и изменить их вручную. – mihajlv