Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Optional Field/element in output
Message
 
To
28/07/2007 08:47:36
General information
Forum:
Visual FoxPro
Category:
XML, XSD
Miscellaneous
Thread ID:
01244346
Message ID:
01244349
Views:
18
>I wonder wether it's possible to display/output a field based on a condition
>
>eg
>
>         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')
>
>
>This produces the following output
>
><?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>
>
>
>The output I would like is
>
><?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>
>
>
>I could put a certain value in the fields I do not need, eg null. Then I could go through the DOM object and remove the nodes with a null value. But I'd like to avoid the if possible
>
>thanks,


Try:
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>
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform