IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Requêtes PostgreSQL Discussion :

Extraire des données d'un XML via XPATH


Sujet :

Requêtes PostgreSQL

  1. #1
    Membre Expert Avatar de QuestVba
    Homme Profil pro
    Enseignant
    Inscrit en
    Juillet 2012
    Messages
    2 475
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : Belgique

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Service public

    Informations forums :
    Inscription : Juillet 2012
    Messages : 2 475
    Par défaut Extraire des données d'un XML via XPATH
    Bonjour à tous,

    Une petite question concernant l'extraction d'une donnée d'un xml via XPATH.

    Voici le xml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    <form xmlns:xformsx="http://xxx.inventivedesigners.com/xforms/extensions" xmlns:x9x_xfdataformatter="http://xxx.inventivedesigners.com/xforms/data-formatting" xmlns:idattxbc="http://xxx.inventivedesigners.com/xsl-fo/ext/attributes/bordercorner" xmlns:idprint="http://xxx.inventivedesigners.com/xsl-fo/ext/print-settings" xmlns:locale="java:java.util.Locale" xmlns:rename="http://xxx.inventivedesigners.com/xslt/rename-to-default-namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:chiba="http://chiba.sourceforge.net/xforms" xmlns:barcodeml="http://xxx.inventivedesigners.com/barcodeml/1.1" xmlns:exslt="http://exslt.org/common" xmlns:idattx="http://xxx.inventivedesigners.com/xsl-fo/ext/attributes" xmlns:st="http://xxx.inventivedesigners.com/xsl-fo/ext/styler" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:widget="http://xxx.inventivedesigners.com/x9x/widget" xmlns:move="http://xxx.inventivedesigners.com/xslt/element-move" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:idx="http://xxx.inventivedesigners.com/xsl-fo/ext/fo-elements" xmlns:x9x_alternative_dataformatter="http://xxx.inventivedesigners.com/xsl/ext/data-formatting" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:iddf="http://xxx.inventivedesigners.com/xforms/data-formatting" xmlns:x9x_dataformatter="java:com.id.saxon.extension.dataformatting.DataFormatter" xmlns:cs="http://xxx.inventivedesigners.com/services" xmlns:idcfg="http://xxx.inventivedesigners.com/x9x/configuration/xpath-extensions/">
      <SuperHeader>
        <PrintInformation>
          <PrInfJobName>CentralPrintJob</PrInfJobName>
          <PrInfTimestamp>2017-03-21T11:42:32.570Z</PrInfTimestamp>
          <PrInfLogicalAddress>drukkerij</PrInfLogicalAddress>
          <PrInfArchive>false</PrInfArchive>
          <PrInfOutput>3</PrInfOutput>
          <PrInfCorrelationID>100005919530</PrInfCorrelationID>
        </PrintInformation>
      </SuperHeader>
      <Document>
        <Header>
          <Message>
            <MessageName>DI5</MessageName>
            <MessageNameDescription>Brief ter informatie</MessageNameDescription>
            <MessageOrder>0</MessageOrder>
            <MessageVersion>1</MessageVersion>
            <MessageLanguage>NL</MessageLanguage>
            <MessageID>049184409978</MessageID>
            <MessageOriginalDate>2017-03-21</MessageOriginalDate>
            <MessageOriginalName>DI5</MessageOriginalName>
            <MessageRegistered>false</MessageRegistered>
            <MessageDuplicate>false</MessageDuplicate>
          </Message>
          <Database>
            <MessageName>DI5</MessageName>
            <MessageLanguage>NL</MessageLanguage>
            <DestinationCountry>België</DestinationCountry>
            <DestinationINSS>9910198565</DestinationINSS>
            <ChildINSS/>
            <RefFileNumber>1492999</RefFileNumber>
            <OfficeCode>2</OfficeCode>
            <AgentNumber>00060843</AgentNumber>
          </Database>
        </Header>
        <RequestGeneral>
          <Office>
            <OfficeCode>2</OfficeCode>
            <OfficeName>P.B.</OfficeName>
            <OfficeStreet>Koning</OfficeStreet>
            <OfficeHouseNr>27</OfficeHouseNr>
            <OfficeZipcode>9000</OfficeZipcode>
            <OfficeCity>Gent</OfficeCity>
            <OfficePhone>09-244 99 99</OfficePhone>
            <OfficeFax>09-222 99 99</OfficeFax>
            <OfficeOpen>0900</OfficeOpen>
            <OfficeClosed>1630</OfficeClosed>
            <OfficeLanguage>NL</OfficeLanguage>
          </Office>
          <Agent>
            <AgentTitle>Mevrouw</AgentTitle>
            <AgentName>DE RYCKE</AgentName>
            <AgentFirstName>LILY</AgentFirstName>
            <AgentPhone>09-244 74 34</AgentPhone>
            <AgentNumber>00060843</AgentNumber>
            <AgentEmail>lily.derycke@famifed.be</AgentEmail>
          </Agent>
          <Destination>
            <DestinationTitleShort>Mevr</DestinationTitleShort>
            <DestinationTitleLong>Mevrouw</DestinationTitleLong>
            <DestinationName>Van Londe</DestinationName>
            <DestinationFirstName>Tan</DestinationFirstName>
            <DestinationStreet>Moor</DestinationStreet>
            <DestinationHouseNr>44</DestinationHouseNr>
            <DestinationPostBox>11</DestinationPostBox>
            <DestinationZipCode>9500</DestinationZipCode>
            <DestinationCity>Aalst</DestinationCity>
            <DestinationCountry>België</DestinationCountry>
            <AddressableId>PERSON_9910198565</AddressableId>
            <DestinationINSS>9910198565</DestinationINSS>
            <DestinationEmail/>
            <DestinationToTheAttentionOfTitle/>
            <DestinationCorrespondenceLanguage>NL</DestinationCorrespondenceLanguage>
          </Destination>
          <Administrator>
            <Destination>
              <DestinationTitleShort>Dhr</DestinationTitleShort>
              <DestinationTitleLong>Mijnheer</DestinationTitleLong>
              <DestinationName>De</DestinationName>
              <DestinationFirstName>Piet</DestinationFirstName>
              <DestinationStreet>Gent</DestinationStreet>
              <DestinationHouseNr>99</DestinationHouseNr>
              <DestinationZipCode>9700</DestinationZipCode>
              <DestinationCity>Oudenaarde</DestinationCity>
              <DestinationCountry>België</DestinationCountry>
              <AddressableId>NPPR_100002938601</AddressableId>
              <DestinationINSS/>
              <DestinationEmail/>
              <DestinationToTheAttentionOfTitle/>
              <DestinationCorrespondenceLanguage>NL</DestinationCorrespondenceLanguage>
            </Destination>
            <Forward>false</Forward>
          </Administrator>
          <References>
            <RefFileNumber>1492999</RefFileNumber>
            <RefInternalRef>1492999</RefInternalRef>
            <RefExternalRef/>
            <RefSignature/>
            <RefSignatureFunction/>
          </References>
        </RequestGeneral>
        <Extended>
          <FreeText>
            <fo:block padding-after="0.7em">
              <fo:inline font-weight="bold">Gelieve zo spoedig het bewijs te leveren dat u nog steeds een uitkering ontvangt van FOD Sociale Zekerheid. Wij vragen een kopie van het rekeninguittreksel met bewijs van de betaling over december 2016. Zonder het betaalbewijs is ons jaarlijks controleformulier niet geldig.</fo:inline>
            </fo:block>
            <fo:block padding-after="0.7em"> </fo:block>
          </FreeText>
          <Option1>
            <fo:block padding-after="0.7em">kinderbijslag</fo:block>
          </Option1>
        </Extended>
      </Document>
    </form>
    Quel mon but ? Extraire les données qui se trouvent dans la balise <fo:block> ? J'arrive à retrouver une autre donnée mais ici, je coince un peu. J'arrive jusque <FreeText>. Comment aller plus loin ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    SELECT 
    	od.document_barcode 
    	,od.document_xml::xml
    	,xpath('/form/Document/Header/Message/MessageName', od.document_xml::xml) AS form 
    	,xpath('/form/Document/Extended/FreeText', od.document_xml::xml) AS Freetext 
    FROM outgoing_documents od 
    WHERE od.document_template = 'DI5'
    ;
    Si vous avez des pistes, je suis preneur ? Un grand merci d'avance.

  2. #2
    Membre Expert Avatar de QuestVba
    Homme Profil pro
    Enseignant
    Inscrit en
    Juillet 2012
    Messages
    2 475
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : Belgique

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Service public

    Informations forums :
    Inscription : Juillet 2012
    Messages : 2 475
    Par défaut
    Je viens de trouver ceci qui me convient.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    SELECT 
        od.document_barcode,
        od.document_xml::xml,
        xpath('/form/Document/Header/Message/MessageName/text()', od.document_xml::xml) AS form,
        xpath('/form/Document/Extended/FreeText/fo:block/text()', od.document_xml::xml, 
                 ARRAY[ARRAY['fo', 'http://www.w3.org/1999/XSL/Format']]) AS freetext
    FROM outgoing_documents od 
    WHERE od.document_template = 'DI5'
    ;

    Mais, en regardant plus de xml, je remarque que l'info se trouve dans la balise <fo:inline> qui se trouve dans la balise <fo:block>. Est-il possible de facilement détecter ce qui est rempli, le tag 1 ou le tag 2 ? Et donc, de récupérer la valeur.

  3. #3
    Rédacteur

    Avatar de SQLpro
    Homme Profil pro
    Expert bases de données / SQL / MS SQL Server / Postgresql
    Inscrit en
    Mai 2002
    Messages
    21 984
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Expert bases de données / SQL / MS SQL Server / Postgresql
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2002
    Messages : 21 984
    Billets dans le blog
    6
    Par défaut
    Citation Envoyé par QuestVba Voir le message
    J...Est-il possible de facilement détecter ce qui est rempli, le tag 1 ou le tag 2 ? Et donc, de récupérer la valeur.
    Le plus simple est de faire une UNION de 2 requêtes...

    A +
    Frédéric Brouard - SQLpro - ARCHITECTE DE DONNÉES - expert SGBDR et langage SQL
    Le site sur les SGBD relationnels et le langage SQL: http://sqlpro.developpez.com/
    Blog SQL, SQL Server, SGBDR : http://blog.developpez.com/sqlpro
    Expert Microsoft SQL Server - M.V.P. (Most valuable Professional) MS Corp.
    Entreprise SQL SPOT : modélisation, conseils, audit, optimisation, formation...
    * * * * * Expertise SQL Server : http://mssqlserver.fr/ * * * * *

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. transformation XML via Xpath
    Par mamat.Net dans le forum XML/XSL et SOAP
    Réponses: 4
    Dernier message: 25/06/2008, 11h51
  2. [DOM] Recherche dans un fichier XML via XPath
    Par Sayrus dans le forum Bibliothèques et frameworks
    Réponses: 6
    Dernier message: 18/06/2007, 16h43
  3. [Débutant] Extraire des parties d'une image via l'interface
    Par Alucard9800XT dans le forum Interfaces Graphiques
    Réponses: 1
    Dernier message: 27/04/2007, 22h55
  4. [xml] comment extraire des donnés xml
    Par Lodos dans le forum XML/XSL et SOAP
    Réponses: 2
    Dernier message: 20/04/2006, 21h47
  5. Extraire des donnés d'un fichier texte
    Par sadsad dans le forum Langage
    Réponses: 2
    Dernier message: 07/02/2006, 15h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo