Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with XMLAdapter

Status
Not open for further replies.

Germancho

Programmer
Jul 9, 2003
36
0
0
VFP 8.0 SP1
Windows XP Pro

I'm new using XMLAdapter and I need to create a XML file based on two cursors ('cabs' and 'pagos') and an XSD schema. Please help me to learn how to do this.

I wrote this code:

Code:
...code to save records on the cursors...

	LOCAL oXML as XMLAdapter
	oXML = CREATEOBJECT('XMLAdapter')
	oXML.LoadXML(lcXSD, .T.)    && path to XSD schema
	oXML.XMLSchemaLocation = lcXML   && XML file
	oXML.ToXML(lcXML)


This is the content of the XSD schema:

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL]   elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:element name="pagos">
    <xs:annotation>
      <xs:documentation>Elemento que encapsula la información del formulario 1001 PAGOS O ABONOS EN CUENTA</xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:attribute name="cpt" use="required">
        <xs:annotation>
          <xs:documentation>Concepto</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:int">
            <xs:minInclusive value="0"/>
            <xs:maxInclusive value="9999"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="tdoc" use="required">
        <xs:annotation>
          <xs:documentation>Tipo de Documento</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:int">
            <xs:minInclusive value="0"/>
            <xs:maxInclusive value="99"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="nid" use="required">
        <xs:annotation>
          <xs:documentation>Número de Identificación</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:minLength value="0"/>
            <xs:maxLength value="20"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="dv" use="optional">
        <xs:annotation>
          <xs:documentation>Digito de Verificación</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:int">
            <xs:minInclusive value="0"/>
            <xs:maxInclusive value="9"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="apl1" use="optional">
        <xs:annotation>
          <xs:documentation>Primer Apellido del informado</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:minLength value="0"/>
            <xs:maxLength value="60"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="apl2" use="optional">
        <xs:annotation>
          <xs:documentation>Segundo Apellido del informado</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:minLength value="0"/>
            <xs:maxLength value="60"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="nom1" use="optional">
        <xs:annotation>
          <xs:documentation>Primer Nombre del informado</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:minLength value="0"/>
            <xs:maxLength value="60"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="nom2" use="optional">
        <xs:annotation>
          <xs:documentation>Otros Nombres del informado</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:minLength value="0"/>
            <xs:maxLength value="60"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="raz" use="optional">
        <xs:annotation>
          <xs:documentation>Razón Social del Informado</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:minLength value="0"/>
            <xs:maxLength value="450"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="dir" use="required">
        <xs:annotation>
          <xs:documentation>Dirección</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:minLength value="0"/>
            <xs:maxLength value="200"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="dpto" use="required">
        <xs:annotation>
          <xs:documentation>Código del Departamento</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:int">
            <xs:minInclusive value="0"/>
            <xs:maxInclusive value="99"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="mun" use="required">
        <xs:annotation>
          <xs:documentation>Código del Municipio</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:int">
            <xs:minInclusive value="0"/>
            <xs:maxInclusive value="999"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="pag" use="required">
        <xs:annotation>
          <xs:documentation>Pago o Abono en cuenta</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:long">
            <xs:minInclusive value="0"/>
            <xs:maxInclusive value="999999999999999999"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <!--xs:attribute name="veco" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:int">
            <xs:minInclusive value="0"/>
            <xs:maxInclusive value="99"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute-->
    </xs:complexType>
  </xs:element>
  <xs:element name="mas">
    <xs:annotation>
      <xs:documentation>Elemento raiz del xml de carga masiva</xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Cab" type="CabType"/>
        <xs:element ref="pagos" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:complexType name="CabType">
    <xs:sequence>
      <xs:element name="Ano" type="xs:gYear" nillable="false">
        <xs:annotation>
          <xs:documentation>Año de envio</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="CodCpt" nillable="false">
        <xs:annotation>
          <xs:documentation>Concepto</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:int">
            <xs:minInclusive value="0"/>
            <xs:maxInclusive value="99"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="Formato" fixed="1001">
        <xs:simpleType>
          <xs:restriction base="xs:positiveInteger">
            <xs:totalDigits value="4"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="Version" type="xs:positiveInteger" fixed="6"/>
      <xs:element name="NumEnvio">
        <xs:annotation>
          <xs:documentation>Numero de envio</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:positiveInteger">
            <xs:totalDigits value="8"/>
            <xs:maxInclusive value="99999999"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="FecEnvio" type="xs:dateTime">
        <xs:annotation>
          <xs:documentation>Fecha de envio</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="FecInicial" type="xs:date">
        <xs:annotation>
          <xs:documentation>Fecha inicial</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="FecFinal" type="xs:date">
        <xs:annotation>
          <xs:documentation>Fecha Final</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="ValorTotal" type="xs:double">
        <xs:annotation>
          <xs:documentation>Valor Total</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="CantReg">
        <xs:annotation>
          <xs:documentation>Cantidad de registros</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:positiveInteger">
            <xs:totalDigits value="4"/>
            <xs:maxInclusive value="9999"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

And the XML file must be like this:

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<mas xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xsi:noNamespaceSchemaLocation="1001.xsd">
	<Cab>
		<Ano>2005</Ano>
		<CodCpt>1</CodCpt>
		<Formato>1001</Formato>
		<Version>6</Version>
		<NumEnvio>1</NumEnvio>
		<FecEnvio>2001-12-17T09:30:47-05:00</FecEnvio>
		<FecInicial>2004-01-01</FecInicial>
		<FecFinal>2004-12-31</FecFinal>
		<ValorTotal>72000000</ValorTotal>
		<CantReg>1</CantReg>
	</Cab>
	<pagos cpt="5001" tdoc="13" nid="19332815" apl1="Pérez" nom1="Roberto" dir="Calle 20 50 10"       
                 dpto="11" mun="1" pag="72000000"/>
</mas>

Thanks yor your help.

Germán Restrepo
Bogotá, Colombia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top