Répétez apres moi :J'aime PBAdonf. J'aime PBAdonf. J'aime PBAdonf.

Le forum (ô combien francophone) des utilisateurs de Powerbuilder.

Recherche rapide

Annonce

Certaines rubriques, dont des cours, sont uniquement visibles par les membres du forum ^^.
Dans la rubrique Liens & Références, vous avez accès à un sommaire de téléchargement, profitez-en !
Il existe maintenant un nouveau TOPIC "Votre CV en Ligne" accessible uniquement par demande.

#1 31-07-2015 10:17:51

infopower  
Membre Power Geek
Lieu: paris
Date d'inscription: 13-04-2011
Messages: 213
Pépites: 1,060
Banque: 0

[RESOLU] Génération des fichier XML

Bonjour,

Je dois générer des données dans des fichiers XML (c'est la première fois que j'utilise XML dans PB)

Avez-vous des liens utiles. Merci par avance.

Dernière modification par infopower (04-08-2015 09:57:13)


la vie est une course et il faut avoir un bon depart

Hors ligne

 

#2 31-07-2015 12:37:53

_francois_  
Bienfaiteur du site
Lieu: TOULOUSE
Date d'inscription: 25-03-2010
Messages: 151
Pépites: 178,983,268,111
Banque: 9,223,372,036,854,776,000

Re: [RESOLU] Génération des fichier XML

Que dois tu faire précisément ?
Prendre le résultat d'une requête et le transformer en XML simple (structure identique pour chaque enregistrement sans trucs optionnels) ?
Dans ce cas tu ouvres ta datawindow et dans le menu tu prends View -> Export/Import Template -> XML
Tu pourrais définir une structure basique pour le XML et après il te suffira dans le programme de faire un saveAs

Exporting to XML
You can export the data in a DataWindow or DataStore object to XML using any of the techniques used for exporting to other formats such as PSR or HTML:

Using the SaveAs method:

ds1.SaveAs("C:\TEMP\Temp.xml", Xml!, true)Using PowerScript dot notation or the Describe method:

ls_xmlstring = dw1.Object.DataWindow.Data.XMLls_xmlstring = dw1.Describe(DataWindow.Data.XML)Using the Save Rows As menu item in the DataWindow painter.

With the Preview view open, select File>Save Rows As, select XML from the Files of Type drop-down list, provide a file name, and click Save. You can use this in the development environment to preview the XML that will be generated at runtime.

When you export data, PowerBuilder uses an export template to specify the content of the generated XML.

Note Default export format
If you have not created or assigned an export template, PowerBuilder uses a default export format. This is the same format used when you create a new default export template. See "Creating templates".

OLE DataWindow objects cannot be exported using a template. You must use the default format.

Si la structure de ton XML est plus complexe il me semble que cette méthode ne va pas fonctionner. Dans ce cas tu dois écrire ta chaîne XML toi même.
Soit en remplissant simplement un string
Soit en utilisant le PBDOM Article PBDJ sur PBDOM
Soit un OLE MSXML

Hors ligne

 

#3 31-07-2015 13:12:02

infopower  
Membre Power Geek
Lieu: paris
Date d'inscription: 13-04-2011
Messages: 213
Pépites: 1,060
Banque: 0

Re: [RESOLU] Génération des fichier XML

Merci pour ce retour rapide.

Il s’agit de :
    Générer les données des requêtes sql dans un fichier XML qui peut contenir plusieurs balises, il ne s’agit pas d’un export simple sous format xml.
    Valider le fichier xml selon un fichier xsd donné.

Je cherche comment alimenter un fichier xml, comment valider son format,…


la vie est une course et il faut avoir un bon depart

Hors ligne

 

#4 31-07-2015 13:40:22

_francois_  
Bienfaiteur du site
Lieu: TOULOUSE
Date d'inscription: 25-03-2010
Messages: 151
Pépites: 178,983,268,111
Banque: 9,223,372,036,854,776,000

Re: [RESOLU] Génération des fichier XML

Pour la validation
d'après l'aide: attention il faut référencer le fichier XSD dans le fichier XML

Code:

XMLParseFile PowerScript function
Description
Parses an XML file and determines whether the file is well formed or complies with a specified grammar.

Syntax
XMLParseFile ( xmlfilename {, validationscheme }{, parsingerrors } {, namespaceprocessing {, schemaprocessing {, schemafullchecking }}})Argument
 Description
 
xmlstring
 A string whose value is the name of the XML file to be parsed.
 
validationscheme (optional)
 A value of the ValSchemeType enumerated datatype specifying the validation method used by the SAX parser. Values are:

ValNever! – Do not report validation errors.

ValAlways! – Always report validation errors.

ValAuto! – (default) Report validation errors only if a grammar is specified.
 
parsingerrors (optional) 
 A string buffer to which error messages can be saved. If not specified or set to null, errors display in a message box.
 
namespaceprocessing (optional)
 A boolean specifying whether name space rules are enforced. When set to true, the parser enforces the constraints and rules defined by the W3C recommendation on namespaces in XML.

If validationscheme is set to ValAlways! or ValAuto!, the document must contain a grammar that supports the use of namespaces.

The default is false.
 
schemaprocessing (optional)
 A boolean specifying whether schema support is enabled. When set to false, the parser does not process any schema found.

If schemaprocessing is true, namespaceprocessing must also be set to true.

The default is false.
 
schemafullchecking (optional) 
 A boolean specifying whether schema constraints are checked. When set to true, the schema grammar is checked for errors. 

Setting schemafullchecking to true has no effect unless schemaprocessing is also set to true.

The default is false.
 

Return Values
Long. Returns 0 for success and one of the following negative values if an error occurs:

-1   Parsing error

-2   Argument error

Usage
Use XMLParseFile to validate an XML file against a DTD or XML schema before proceeding with additional processing. 

If no DTD or schema is included or referenced in the file, XMLParseFile checks whether the document contains well-formed XML. If the XML document fails validation or is not well–formed, XMLParseFile returns -1. 

Because XSD You can also check the well-formedness of an XSD file because they are in XML format. The validation scheme must be ValAuto!, which is the default validation scheme.

To suppress the display of message boxes if errors occur, specify a string value for the parsingerrors argument.

The files pbxercesNN.dll and xerces-c_XX.dll, where NN represents the PowerBuilder version and XX represents the Xerces version, must be deployed with the other PowerBuilder runtime files in the search path of any application or component that uses this function.

Examples
These statements parse an XML document. If a DTD is included or referenced, the document is validated. Otherwise the parser checks for well-formedness. If the document passes validation, it is imported into a DataWindow control:

long ll_ret ll_ret = XMLParseFile("c:\temp\mydoc.xml")if ll_ret = 0 then dw_1.ImportFile("c:\temp\mydoc.xml")These statements parse an XML document and save any errors in the string variable ls_err. If errors occur, no message boxes display. If a DTD is included or referenced, the document is validated. Otherwise the parser checks for well–formedness:

long ll_retstring ls_errll_ret = XMLParseFile("c:\temp\mydoc.xml", ls_err)These statements parse an XML document. If an XMLSchema is included or referenced, the document is validated, otherwise the parser checks for well–formedness:

long ll_retll_ret = XMLParseFile("c:\temp\mydoc.xml", TRUE, TRUE)These statements parse an XML document, validate against a given XML schema, and save any errors that occur in a string variable. If errors occur, no message boxes display. If no schema is included or referenced in the file, XMLParseFile returns -1:

long ll_retstring ls_errll_ret = XMLParseFile("c:\temp\mydoc.xml", ValAlways!,   ls_err, TRUE, TRUE)These statements parse an XML document, validate against a given XML schema, and parse the schema itself for additional errors. If no schema is included or referenced in the file, XMLParseFile returns -1:

long ll_retstring ls_errll_ret = XMLParseFile("c:\temp\mydoc.xml", ValAlways!,   ls_err, TRUE, TRUE, TRUE)These statements parse an XML document, validate against a given DTD, and save any errors that occur in a string variable. If errors occur, no message boxes display. If no DTD is included or referenced in the file, XMLParseFile returns –1:

long ll_retstring ls_errll_ret = XMLParseFile("c:\temp\mydoc.xml", ValAlways!,   ls_err)These statements parse an XSD file and test it for well-formedness. You must use ValAuto! when you parse an XSD file because there is no external schema associated with it. However, you do not need to specify the option when you call the function because it is the default validation method:

long ll_retll_ret = XMLParseFile ("c:\mydoc.xsd")

Sinon avec l'OLE MSXML, un bout de mon code donc j'ai zappé des trucs

Code: pb

oleobject  loo_msxml, loo_xsd, loo_object_cache
boolean     lb_xml_valide = true

loo_msxml = CREATE oleobject
loo_xsd = CREATE oleobject
loo_object_cache = CREATE oleobject

  loo_msxml.connectToNewObject("Msxml2.DOMDocument.6.0")
  loo_xsd.connectToNewObject("Msxml2.DOMDocument.6.0")

  loo_msxml.async = false
  loo_msxml.validateOnParse = true
  
  loo_xsd.async = false
  loo_xsd.validateOnParse= true
  loo_xsd.load(ls_fichier_xsd)
  
  loo_object_cache.connectToNewObject("Msxml2.XMLSchemaCache.6.0")
  try
    loo_object_cache.add("urn:MonNamespace",ls_fichier_xsd)
  catch (OLERuntimeError ltre)
    lb_xml_valide = false
  end try
  
  if lb_xml_valide then

    loo_msxml.schemas = loo_object_cache
    loo_msxml.loadXML(ls_fichier_xml)
    
    loo_error = loo_msxml.parseError
    if integer(loo_error.errorCode) <> 0 then
      ls_libelle_retour_lot_comp = string(loo_error.errorCode) + ' - ' + string(loo_error.reason)
      lb_xml_valide = false
      ll_ret = -119
    else
....................


Pour construire la fichier XML par chez nous on construit simplement une chaîne de caractères et on fait un filewrite derrière si besoin

Hors ligne

 

#5 31-07-2015 13:51:53

infopower  
Membre Power Geek
Lieu: paris
Date d'inscription: 13-04-2011
Messages: 213
Pépites: 1,060
Banque: 0

Re: [RESOLU] Génération des fichier XML

Merci beaucoup


la vie est une course et il faut avoir un bon depart

Hors ligne

 

Pied de page des forums

Propulsé par FluxBB 1.2.22