Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Xml trouble
#1
Hello! I have one xml file, ex.
<?xml version="1.0" encoding="UTF-8"?>
<crossword-compiler xmlns="http://crossword.info/xml/crossword-compiler"><rectangular-puzzle xmlns="http://crossword.info/xml/rectangular-puzzle" alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"><metadata><title></title><creator></creator><copyright></copyright><description></description></metadata><crossword><grid width="6" height="6"><grid-look numbering-scheme="none" cell-size-in-pixels="34" clue-square-divider-width="0.7"/><cell x="1" y="2" type="clue"><clue word="1">Clue</clue></cell><cell x="1" y="3" type="clue"><clue word="2">Clue</clue></cell><cell x="1" y="4" type="clue"><clue word="3">Clue</clue></cell><cell x="1" y="5" type="clue"><clue word="4">Clue</clue></cell><cell x="1" y="6" type="clue"><clue word="5">Clue</clue></cell><cell x="2" y="1" type="clue"><clue word="6">Clue</clue></cell><cell x="2" y="2" solution="V"><arrow from="top" to="bottom"/><arrow from="left" to="right"/></cell><cell x="2" y="3" solution="O"><arrow from="left" to="right"/></cell><cell x="2" y="4" solution="N"><arrow from="left" to="right"/></cell><cell x="2" y="5" solution="A"><arrow from="left" to="right"/></cell><cell x="2" y="6" solution="L"><arrow from="left" to="right"/></cell><cell x="3" y="1" type="clue"><clue word="7">Clue</clue></cell><cell x="3" y="2" solution="I"><arrow from="top" to="bottom"/></cell><cell x="3" y="3" solution="S"/><cell x="3" y="4" solution="O"/><cell x="3" y="5" solution="L"/><cell x="3" y="6" solution="A"/><cell x="4" y="1" type="clue"><clue word="8">Clue</clue></cell><cell x="4" y="2" solution="Z"><arrow from="top" to="bottom"/></cell><cell x="4" y="3" solution="A"/><cell x="4" y="4" solution="M"/><cell x="4" y="5" solution="A"/><cell x="4" y="6" solution="T"/><cell x="5" y="1" type="clue"><clue word="9">Clue</clue></cell><cell x="5" y="2" solution="E"><arrow from="top" to="bottom"/></cell><cell x="5" y="3" solution="K"/><cell x="5" y="4" solution="E"/><cell x="5" y="5" solution="K"/><cell x="5" y="6" solution="E"/><cell x="6" y="1" type="clue"><clue word="10">Clue</clue></cell><cell x="6" y="2" solution="Z"><arrow from="top" to="bottom"/></cell><cell x="6" y="3" solution="A"/><cell x="6" y="4" solution="N"/><cell x="6" y="5" solution="Ó"/><cell x="6" y="6" solution="T"/></grid><word id="1" x="2-6" y="2"/><word id="2" x="2-6" y="3"/><word id="3" x="2-6" y="4"/><word id="4" x="2-6" y="5"/><word id="5" x="2-6" y="6"/><word id="6" x="2" y="2-6"/><word id="7" x="3" y="2-6"/><word id="8" x="4" y="2-6"/><word id="9" x="5" y="2-6"/><word id="10" x="6" y="2-6"/><clues ordering="normal"><title><b>Across</b></title><clue word="1" number="1" format="5">NEDVESÍT</clue><clue word="2" number="6" format="5">JAPÁN ELEKTR. M.</clue><clue word="3" number="7" format="5">NÉV (LAT.)</clue><clue word="4" number="8" format="5">Polanski filmje</clue><clue word="5" number="9" format="5">... ANGUIS IN HERBA</clue></clues><clues ordering="normal"><title><b>Down</b></title><clue word="6" number="1" format="5">PONTOK SORA</clue><clue word="7" number="2" format="5">SZIGET (OL.)</clue><clue word="8" number="3" format="5">AROMA</clue><clue word="9" number="4" format="5">KAMERUNI FOCISTA</clue><clue word="10" number="5" format="5">FÉLCSERJE</clue></clues></crossword></rectangular-puzzle></crossword-compiler>

Is output of program, and the size is variable. The expression "<clue word="1">" appear twice, first have value "Clue", second have value "NEDVESÍT". I want to replace the first value with the second value (the second value remain), with iterating from "<clue word="1">" to its max value (in example "<clue word="10">". Thank you for help!
#2
To replace 1st <clue word="1"> value with 2nd <clue word="1"> value
Function XmlReplacementExample
Code:
Copy      Help
str xml=
;<?xml version="1.0" encoding="UTF-8"?>
;<crossword-compiler xmlns="http://crossword.info/xml/crossword-compiler"><rectangular-puzzle xmlns="http://crossword.info/xml/rectangular-puzzle" alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"><metadata><title></title><creator></creator><copyright></copyright><description></description></metadata><crossword><grid width="6" height="6"><grid-look numbering-scheme="none" cell-size-in-pixels="34" clue-square-divider-width="0.7"/><cell x="1" y="2" type="clue"><clue word="1">Clue</clue></cell><cell x="1" y="3" type="clue"><clue word="2">Clue</clue></cell><cell x="1" y="4" type="clue"><clue word="3">Clue</clue></cell><cell x="1" y="5" type="clue"><clue word="4">Clue</clue></cell><cell x="1" y="6" type="clue"><clue word="5">Clue</clue></cell><cell x="2" y="1" type="clue"><clue word="6">Clue</clue></cell><cell x="2" y="2" solution="V"><arrow from="top" to="bottom"/><arrow from="left" to="right"/></cell><cell x="2" y="3" solution="O"><arrow from="left" to="right"/></cell><cell x="2" y="4" solution="N"><arrow from="left" to="right"/></cell><cell x="2" y="5" solution="A"><arrow from="left" to="right"/></cell><cell x="2" y="6" solution="L"><arrow from="left" to="right"/></cell><cell x="3" y="1" type="clue"><clue word="7">Clue</clue></cell><cell x="3" y="2" solution="I"><arrow from="top" to="bottom"/></cell><cell x="3" y="3" solution="S"/><cell x="3" y="4" solution="O"/><cell x="3" y="5" solution="L"/><cell x="3" y="6" solution="A"/><cell x="4" y="1" type="clue"><clue word="8">Clue</clue></cell><cell x="4" y="2" solution="Z"><arrow from="top" to="bottom"/></cell><cell x="4" y="3" solution="A"/><cell x="4" y="4" solution="M"/><cell x="4" y="5" solution="A"/><cell x="4" y="6" solution="T"/><cell x="5" y="1" type="clue"><clue word="9">Clue</clue></cell><cell x="5" y="2" solution="E"><arrow from="top" to="bottom"/></cell><cell x="5" y="3" solution="K"/><cell x="5" y="4" solution="E"/><cell x="5" y="5" solution="K"/><cell x="5" y="6" solution="E"/><cell x="6" y="1" type="clue"><clue word="10">Clue</clue></cell><cell x="6" y="2" solution="Z"><arrow from="top" to="bottom"/></cell><cell x="6" y="3" solution="A"/><cell x="6" y="4" solution="N"/><cell x="6" y="5" solution="Ó"/><cell x="6" y="6" solution="T"/></grid><word id="1" x="2-6" y="2"/><word id="2" x="2-6" y="3"/><word id="3" x="2-6" y="4"/><word id="4" x="2-6" y="5"/><word id="5" x="2-6" y="6"/><word id="6" x="2" y="2-6"/><word id="7" x="3" y="2-6"/><word id="8" x="4" y="2-6"/><word id="9" x="5" y="2-6"/><word id="10" x="6" y="2-6"/><clues ordering="normal"><title><b>Across</b></title><clue word="1" number="1" format="5">NEDVESÍT</clue><clue word="2" number="6" format="5">JAPÁN ELEKTR. M.</clue><clue word="3" number="7" format="5">NÉV (LAT.)</clue><clue word="4" number="8" format="5">Polanski filmje</clue><clue word="5" number="9" format="5">... ANGUIS IN HERBA</clue></clues><clues ordering="normal"><title><b>Down</b></title><clue word="6" number="1" format="5">PONTOK SORA</clue><clue word="7" number="2" format="5">SZIGET (OL.)</clue><clue word="8" number="3" format="5">AROMA</clue><clue word="9" number="4" format="5">KAMERUNI FOCISTA</clue><clue word="10" number="5" format="5">FÉLCSERJE</clue></clues></crossword></rectangular-puzzle></crossword-compiler>

out
IXml x._create
x.FromString(xml)
ARRAY(IXmlNode) a; int i
x.Path("//clue[@word='1']" a 1)
a[0].Value=a[1].Value
x.ToString(xml)
out xml


to replace all 1st <clue word="number">Clue</clue> values with the 2nd <clue word="number">someword</clue>
Function XmlReplacementExample2
Code:
Copy      Help
str xml=
;<?xml version="1.0" encoding="UTF-8"?>
;<crossword-compiler xmlns="http://crossword.info/xml/crossword-compiler"><rectangular-puzzle xmlns="http://crossword.info/xml/rectangular-puzzle" alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"><metadata><title></title><creator></creator><copyright></copyright><description></description></metadata><crossword><grid width="6" height="6"><grid-look numbering-scheme="none" cell-size-in-pixels="34" clue-square-divider-width="0.7"/><cell x="1" y="2" type="clue"><clue word="1">Clue</clue></cell><cell x="1" y="3" type="clue"><clue word="2">Clue</clue></cell><cell x="1" y="4" type="clue"><clue word="3">Clue</clue></cell><cell x="1" y="5" type="clue"><clue word="4">Clue</clue></cell><cell x="1" y="6" type="clue"><clue word="5">Clue</clue></cell><cell x="2" y="1" type="clue"><clue word="6">Clue</clue></cell><cell x="2" y="2" solution="V"><arrow from="top" to="bottom"/><arrow from="left" to="right"/></cell><cell x="2" y="3" solution="O"><arrow from="left" to="right"/></cell><cell x="2" y="4" solution="N"><arrow from="left" to="right"/></cell><cell x="2" y="5" solution="A"><arrow from="left" to="right"/></cell><cell x="2" y="6" solution="L"><arrow from="left" to="right"/></cell><cell x="3" y="1" type="clue"><clue word="7">Clue</clue></cell><cell x="3" y="2" solution="I"><arrow from="top" to="bottom"/></cell><cell x="3" y="3" solution="S"/><cell x="3" y="4" solution="O"/><cell x="3" y="5" solution="L"/><cell x="3" y="6" solution="A"/><cell x="4" y="1" type="clue"><clue word="8">Clue</clue></cell><cell x="4" y="2" solution="Z"><arrow from="top" to="bottom"/></cell><cell x="4" y="3" solution="A"/><cell x="4" y="4" solution="M"/><cell x="4" y="5" solution="A"/><cell x="4" y="6" solution="T"/><cell x="5" y="1" type="clue"><clue word="9">Clue</clue></cell><cell x="5" y="2" solution="E"><arrow from="top" to="bottom"/></cell><cell x="5" y="3" solution="K"/><cell x="5" y="4" solution="E"/><cell x="5" y="5" solution="K"/><cell x="5" y="6" solution="E"/><cell x="6" y="1" type="clue"><clue word="10">Clue</clue></cell><cell x="6" y="2" solution="Z"><arrow from="top" to="bottom"/></cell><cell x="6" y="3" solution="A"/><cell x="6" y="4" solution="N"/><cell x="6" y="5" solution="Ó"/><cell x="6" y="6" solution="T"/></grid><word id="1" x="2-6" y="2"/><word id="2" x="2-6" y="3"/><word id="3" x="2-6" y="4"/><word id="4" x="2-6" y="5"/><word id="5" x="2-6" y="6"/><word id="6" x="2" y="2-6"/><word id="7" x="3" y="2-6"/><word id="8" x="4" y="2-6"/><word id="9" x="5" y="2-6"/><word id="10" x="6" y="2-6"/><clues ordering="normal"><title><b>Across</b></title><clue word="1" number="1" format="5">NEDVESÍT</clue><clue word="2" number="6" format="5">JAPÁN ELEKTR. M.</clue><clue word="3" number="7" format="5">NÉV (LAT.)</clue><clue word="4" number="8" format="5">Polanski filmje</clue><clue word="5" number="9" format="5">... ANGUIS IN HERBA</clue></clues><clues ordering="normal"><title><b>Down</b></title><clue word="6" number="1" format="5">PONTOK SORA</clue><clue word="7" number="2" format="5">SZIGET (OL.)</clue><clue word="8" number="3" format="5">AROMA</clue><clue word="9" number="4" format="5">KAMERUNI FOCISTA</clue><clue word="10" number="5" format="5">FÉLCSERJE</clue></clues></crossword></rectangular-puzzle></crossword-compiler>

out
IXml x._create
x.FromString(xml)
ARRAY(IXmlNode) a; int i ii
x.Path("//clue[@word!='0']" a 1)
int nv=a.len/2
for i 0 nv
,IXmlNode n=a[i]
,a[i].Value=a[i+nv].Value
x.ToString(xml)
out xml
#3
Smile 
Perfect!  Smile Thank you Sir!


Forum Jump:


Users browsing this thread: 1 Guest(s)