> create cursor test ; > ( need_a1 L, ; > a0 c(10), ; > a1 c(10), ; > a2 c(10) ; > ) > > insert into test values( .T., '1', '10', '11') > insert into test values( .F., '2', '20', '21') > > local xml, i, s > xml = createobject('xmladapter') > > =xml.AddTableSchema('test') > xml.xmlSchemalocation='' > > i = m.xml.Tables(1).Fields.GetKey(strconv('need_a1', 12)) > assert !empty(m.i) > = m.xml.Tables(1).Fields.Remove(m.i) > > = m.xml.ToXml('s') >>
><?xml version = "1.0" encoding="Windows-1252" standalone="yes"?> ><VFPDataSet> > <test> > <a0>1</a0> > <a1>10</a1> > <a2>11</a2> && do not need this > </test> > <test> > <a0>2</a0> > <a1>20</a1> && here I do not need this line > <a2>21</a2> > </test> ></VFPDataSet> >>
><?xml version = "1.0" encoding="Windows-1252" standalone="yes"?> ><VFPDataSet> > <test> > <a0>1</a0> > <a1>10</a1> > </test> > <test> > <a0>2</a0> > <a2>21</a2> > </test> ></VFPDataSet> >>
CLEAR SET ASSERTS ON create cursor test ; ( need_a1 L, ; a0 c(10), ; a1 c(10), ; a2 c(10) ; ) insert into test values( .t., '1', '10', '11') insert into test values( .f., '2', '20', '21') REPLACE a1 WITH IIF(need_a1,a1,[]),; a2 WITH IIF(need_a1,[],a2) ALL local xml, i, s xml = createobject('xmladapter') =xml.AddTableSchema('test') xml.xmlSchemalocation='' o1 = m.xml.Tables(1).Fields = m.xml.ToXml('s')That will generate the following output:
<?xml version = "1.0" encoding="Windows-1252" standalone="yes"?> <VFPDataSet> <test> <need_a1>true</need_a1> <a0>1</a0> <a1>10</a1> <a2/> </test> <test> <need_a1>false</need_a1> <a0>2</a0> <a1/> <a2>21</a2> </test> </VFPDataSet>