Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with XMLToCursor()
Message
From
17/09/2002 14:22:32
 
 
To
17/09/2002 03:36:56
General information
Forum:
Visual FoxPro
Category:
XML, XSD
Miscellaneous
Thread ID:
00701121
Message ID:
00701408
Views:
12
>I need help in using the xmltocursor() function.
>When i import XML data, if one of the fields from the XML file has a dot (.) in it's name, that field will not be correctly imported.
>
>Example:
>
>The following is an example of two lines from the XML file:
>
><item Codigo="117762" Descricao="BANANAS IMPORTADAS" Preco="1.05"
U.M.="KG" Fam_Pai="001" Familia="001001" IVA="5" Data_Inicio="2002/09/10"
Data_Validade="" Moeda="EUR" Al_NAl_Tab_Taras="6" />
>
><item Codigo="117768" Descricao="ANANAZ MADEIRA" Preco="1.12"
U.M.="KG" Fam_Pai="001" Familia="001001" IVA="5" Data_Inicio="2002/09/10"
Data_Validade="" Moeda="EUR" Al_NAl_Tab_Taras="6" />
>
>Look at the field "U.M." and to what happens when i use xmltocursor() to create the cursor "Cursor1":
>
>CURSOR1:
>CODIGO  DESCRICAO                PRECO  U       FAM_PAI   ...
>117762  BANANAS IMPORTADAS        1.05          001
>117768  ANANAZ MADEIRA            1.12          001
>
>The code i used was:
>X = XMLTOCURSOR(m.caminho, "Cursor1", 1536)
>
>Where "m.caminho" it's a string with the name and location of the XML file.

Sergey already explained you why you cannot use XMLTOCURSOR() in this case. In alternative to programmatically parse the XML document, you can apply a stylesheet to it prior to execute XMLTOCURSOR(). This technique is used in a September'2002 issue of UT Magazine tip (STRCONV()...). In your case, the reencoder stylesheet could be something like:
   m.lcReencoder = [<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">] + NL +;
            [<xsl:output method="xml" ] +;
            [encoding="] + LOWER(ALLTRIM(m.tcTargetEncoding)) + [" ] +;
            [omit-xml-declaration="no" indent="yes"/> ] + NL +;
            [<xsl:template match="/ | @* | node()">] + NL +;
            [<xsl:copy>] + NL +;
            [<xsl:apply-templates select="@* | node()"/>] + NL +;
            [</xsl:copy>] + NL +;
            [</xsl:template>] + NL +;
            [<xsl:template match="@U.M.">] + NL +;
            [<xsl:attribute name="UM"><xsl:value-of select="current()"/></xsl:attribute>] + NL +;
            [</xsl:template>] + NL +;
            [</xsl:stylesheet>] + NL
(to see the reencoder open the code document and ask for its source).

After this reencoding, the resulting XML file will look like:
<?xml version="1.0" encoding="iso-8859-1"?>
<items>
	<item Codigo="117762" Descricao="BANANAS IMPORTADAS" Preco="1.05" UM="KG"
Fam_Pai="001" Familia="001001" IVA="5" Data_Inicio="2002/09/10"
Data_Validade="" Moeda="EUR" Al_NAl_Tab_Taras="6">
	</item>
	<item Codigo="117768" Descricao="ANANAZ MADEIRA" Preco="1.12" UM="KG"
Fam_Pai="001" Familia="001001" IVA="5" Data_Inicio="2002/09/10"
Data_Validade="" Moeda="EUR" Al_NAl_Tab_Taras="6">
	</item>
</items>
(items element were inserted in the XML document) and will be ready to XMLTOCURSOR() processing.
----------------------------------
António Tavares Lopes
Previous
Reply
Map
View

Click here to load this message in the networking platform