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

XSL/XSLT/XPATH XML Discussion :

Syntaxe XPath pour obtenir tous les éléments à partir d'un noeud


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Membre expérimenté
    Avatar de FRED.G
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    1 032
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 1 032
    Points : 1 505
    Points
    1 505
    Par défaut Syntaxe XPath pour obtenir tous les éléments à partir d'un noeud
    Bonjour,

    j'aimerais savoir quelle est la syntaxe XPath pour obtenir la hiérarchie des éléments (avec les noms et valeurs de leurs attributs) à partir de cet élément :
    <edmx:ConceptualModels>
    dans le fichier suivant (cf PJ pour plus de lisibilité) :
    Code xml : 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
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    <?xml version="1.0" encoding="utf-8"?>
    <edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
      <edmx:Runtime>
        <!-- SSDL content -->
        <edmx:StorageModels>
        <Schema Namespace="NorthwindModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">
            <EntityContainer Name="NorthwindModelStoreContainer">
              <EntitySet Name="Categories" EntityType="NorthwindModel.Store.Categories" store:Type="Tables" Schema="dbo" />
              <EntitySet Name="Customers" EntityType="NorthwindModel.Store.Customers" store:Type="Tables" Schema="dbo" />
              <EntitySet Name="Orders" EntityType="NorthwindModel.Store.Orders" store:Type="Tables" Schema="dbo" />
              <AssociationSet Name="FK_Orders_Customers" Association="NorthwindModel.Store.FK_Orders_Customers">
                <End Role="Customers" EntitySet="Customers" />
                <End Role="Orders" EntitySet="Orders" />
              </AssociationSet>
            </EntityContainer>
            <EntityType Name="Categories">
              <Key>
                <PropertyRef Name="CategoryID" />
              </Key>
              <Property Name="CategoryID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
              <Property Name="CategoryName" Type="nvarchar" Nullable="false" MaxLength="15" />
              <Property Name="Description" Type="ntext" />
              <Property Name="Picture" Type="image" />
            </EntityType>
            <EntityType Name="Customers">
              <Key>
                <PropertyRef Name="CustomerID" />
              </Key>
              <Property Name="CustomerID" Type="nchar" Nullable="false" MaxLength="5" />
              <Property Name="CompanyName" Type="nvarchar" Nullable="false" MaxLength="40" />
              <Property Name="ContactName" Type="nvarchar" MaxLength="30" />
              <Property Name="ContactTitle" Type="nvarchar" MaxLength="30" />
              <Property Name="Address" Type="nvarchar" MaxLength="60" />
              <Property Name="City" Type="nvarchar" MaxLength="15" />
              <Property Name="Region" Type="nvarchar" MaxLength="15" />
              <Property Name="PostalCode" Type="nvarchar" MaxLength="10" />
              <Property Name="Country" Type="nvarchar" MaxLength="15" />
              <Property Name="Phone" Type="nvarchar" MaxLength="24" />
              <Property Name="Fax" Type="nvarchar" MaxLength="24" />
            </EntityType>
            <EntityType Name="Orders">
              <Key>
                <PropertyRef Name="OrderID" />
              </Key>
              <Property Name="OrderID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
              <Property Name="CustomerID" Type="nchar" MaxLength="5" />
              <Property Name="EmployeeID" Type="int" />
              <Property Name="OrderDate" Type="datetime" />
              <Property Name="RequiredDate" Type="datetime" />
              <Property Name="ShippedDate" Type="datetime" />
              <Property Name="ShipVia" Type="int" />
              <Property Name="Freight" Type="money" />
              <Property Name="ShipName" Type="nvarchar" MaxLength="40" />
              <Property Name="ShipAddress" Type="nvarchar" MaxLength="60" />
              <Property Name="ShipCity" Type="nvarchar" MaxLength="15" />
              <Property Name="ShipRegion" Type="nvarchar" MaxLength="15" />
              <Property Name="ShipPostalCode" Type="nvarchar" MaxLength="10" />
              <Property Name="ShipCountry" Type="nvarchar" MaxLength="15" />
            </EntityType>
            <Association Name="FK_Orders_Customers">
              <End Role="Customers" Type="NorthwindModel.Store.Customers" Multiplicity="0..1" />
              <End Role="Orders" Type="NorthwindModel.Store.Orders" Multiplicity="*" />
              <ReferentialConstraint>
                <Principal Role="Customers">
                  <PropertyRef Name="CustomerID" />
                </Principal>
                <Dependent Role="Orders">
                  <PropertyRef Name="CustomerID" />
                </Dependent>
              </ReferentialConstraint>
            </Association>
          </Schema></edmx:StorageModels>
        <!-- CSDL content -->
        <edmx:ConceptualModels>
          <Schema Namespace="NorthwindModel" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
            <EntityContainer Name="NorthwindEntities">
              <EntitySet Name="Customers" EntityType="NorthwindModel.Customers" />
              <EntitySet Name="Orders" EntityType="NorthwindModel.Orders" />
              <AssociationSet Name="FK_Orders_Customers" Association="NorthwindModel.FK_Orders_Customers">
                <End Role="Customers" EntitySet="Customers" />
                <End Role="Orders" EntitySet="Orders" />
              </AssociationSet>
              </EntityContainer>
            <EntityType Name="Customers">
              <Key>
                <PropertyRef Name="CustomerID" />
              </Key>
              <Property Name="CustomerID" Type="String" Nullable="false" MaxLength="5" Unicode="true" FixedLength="true" />
              <Property Name="CompanyName" Type="String" Nullable="false" MaxLength="40" Unicode="true" FixedLength="false" />
              <Property Name="ContactName" Type="String" MaxLength="30" Unicode="true" FixedLength="false" />
              <Property Name="ContactTitle" Type="String" MaxLength="30" Unicode="true" FixedLength="false" />
              <Property Name="Address" Type="String" MaxLength="60" Unicode="true" FixedLength="false" />
              <Property Name="City" Type="String" MaxLength="15" Unicode="true" FixedLength="false" />
              <Property Name="Region" Type="String" MaxLength="15" Unicode="true" FixedLength="false" />
              <Property Name="PostalCode" Type="String" MaxLength="10" Unicode="true" FixedLength="false" />
              <Property Name="Country" Type="String" MaxLength="15" Unicode="true" FixedLength="false" />
              <Property Name="Phone" Type="String" MaxLength="24" Unicode="true" FixedLength="false" />
              <Property Name="Fax" Type="String" MaxLength="24" Unicode="true" FixedLength="false" />
              <NavigationProperty Name="Orders" Relationship="NorthwindModel.FK_Orders_Customers" FromRole="Customers" ToRole="Orders" />
            </EntityType>
            <EntityType Name="Orders">
              <Key>
                <PropertyRef Name="OrderID" />
              </Key>
              <Property Name="OrderID" Type="Int32" Nullable="false" />
              <Property Name="EmployeeID" Type="Int32" />
              <Property Name="OrderDate" Type="DateTime" />
              <Property Name="RequiredDate" Type="DateTime" />
              <Property Name="ShippedDate" Type="DateTime" />
              <Property Name="ShipVia" Type="Int32" />
              <Property Name="Freight" Type="Decimal" Precision="19" Scale="4" />
              <Property Name="ShipName" Type="String" MaxLength="40" Unicode="true" FixedLength="false" />
              <Property Name="ShipAddress" Type="String" MaxLength="60" Unicode="true" FixedLength="false" />
              <Property Name="ShipCity" Type="String" MaxLength="15" Unicode="true" FixedLength="false" />
              <Property Name="ShipRegion" Type="String" MaxLength="15" Unicode="true" FixedLength="false" />
              <Property Name="ShipPostalCode" Type="String" MaxLength="10" Unicode="true" FixedLength="false" />
              <Property Name="ShipCountry" Type="String" MaxLength="15" Unicode="true" FixedLength="false" />
              <NavigationProperty Name="Customers" Relationship="NorthwindModel.FK_Orders_Customers" FromRole="Orders" ToRole="Customers" />
            </EntityType>
            <Association Name="FK_Orders_Customers">
              <End Role="Customers" Type="NorthwindModel.Customers" Multiplicity="0..1" />
              <End Role="Orders" Type="NorthwindModel.Orders" Multiplicity="*" />
            </Association>
            </Schema>
        </edmx:ConceptualModels>
        <!-- C-S mapping content -->
        <edmx:Mappings>
          <Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
            <EntityContainerMapping StorageEntityContainer="NorthwindModelStoreContainer" CdmEntityContainer="NorthwindEntities">
              <EntitySetMapping Name="Customers">
                <EntityTypeMapping TypeName="IsTypeOf(NorthwindModel.Customers)">
                  <MappingFragment StoreEntitySet="Customers">
                    <ScalarProperty Name="CustomerID" ColumnName="CustomerID" />
                    <ScalarProperty Name="CompanyName" ColumnName="CompanyName" />
                    <ScalarProperty Name="ContactName" ColumnName="ContactName" />
                    <ScalarProperty Name="ContactTitle" ColumnName="ContactTitle" />
                    <ScalarProperty Name="Address" ColumnName="Address" />
                    <ScalarProperty Name="City" ColumnName="City" />
                    <ScalarProperty Name="Region" ColumnName="Region" />
                    <ScalarProperty Name="PostalCode" ColumnName="PostalCode" />
                    <ScalarProperty Name="Country" ColumnName="Country" />
                    <ScalarProperty Name="Phone" ColumnName="Phone" />
                    <ScalarProperty Name="Fax" ColumnName="Fax" />
                  </MappingFragment>
                </EntityTypeMapping>
              </EntitySetMapping>
              <EntitySetMapping Name="Orders">
                <EntityTypeMapping TypeName="IsTypeOf(NorthwindModel.Orders)">
                  <MappingFragment StoreEntitySet="Orders">
                    <ScalarProperty Name="OrderID" ColumnName="OrderID" />
                    <ScalarProperty Name="EmployeeID" ColumnName="EmployeeID" />
                    <ScalarProperty Name="OrderDate" ColumnName="OrderDate" />
                    <ScalarProperty Name="RequiredDate" ColumnName="RequiredDate" />
                    <ScalarProperty Name="ShippedDate" ColumnName="ShippedDate" />
                    <ScalarProperty Name="ShipVia" ColumnName="ShipVia" />
                    <ScalarProperty Name="Freight" ColumnName="Freight" />
                    <ScalarProperty Name="ShipName" ColumnName="ShipName" />
                    <ScalarProperty Name="ShipAddress" ColumnName="ShipAddress" />
                    <ScalarProperty Name="ShipCity" ColumnName="ShipCity" />
                    <ScalarProperty Name="ShipRegion" ColumnName="ShipRegion" />
                    <ScalarProperty Name="ShipPostalCode" ColumnName="ShipPostalCode" />
                    <ScalarProperty Name="ShipCountry" ColumnName="ShipCountry" />
                  </MappingFragment>
                </EntityTypeMapping>
              </EntitySetMapping>
              <AssociationSetMapping Name="FK_Orders_Customers" TypeName="NorthwindModel.FK_Orders_Customers" StoreEntitySet="Orders">
                <EndProperty Name="Customers">
                  <ScalarProperty Name="CustomerID" ColumnName="CustomerID" />
                </EndProperty>
                <EndProperty Name="Orders">
                  <ScalarProperty Name="OrderID" ColumnName="OrderID" />
                </EndProperty>
                <Condition ColumnName="CustomerID" IsNull="false" />
              </AssociationSetMapping>
              </EntityContainerMapping>
          </Mapping>
        </edmx:Mappings>
      </edmx:Runtime>
      <edmx:Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx">
        <edmx:Connection>
          <DesignerInfoPropertySet>
            <DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
          </DesignerInfoPropertySet>
        </edmx:Connection>
        <edmx:Options>
          <DesignerInfoPropertySet>
            <DesignerProperty Name="ValidateOnBuild" Value="true" />
          </DesignerInfoPropertySet>
        </edmx:Options>
        <edmx:Diagrams >
    <Diagram Name="Northwind">
    <EntityTypeShape EntityType="NorthwindModel.Customers" PointX="0.75" PointY="1.25" Width="1.5" Height="3.3263964843749996" IsExpanded="true" />
    <EntityTypeShape EntityType="NorthwindModel.Orders" PointX="3" PointY="1" Width="1.5" Height="3.7109993489583331" IsExpanded="true" />
    <AssociationConnector Association="NorthwindModel.FK_Orders_Customers" ManuallyRouted="false">
    <ConnectorPoint PointX="2.25" PointY="2.9131982421875" />
    <ConnectorPoint PointX="3" PointY="2.9131982421875" /></AssociationConnector>
            </Diagram></edmx:Diagrams>
      </edmx:Designer>
    </edmx:Edmx>

    Je connais mal XPath, et surtout je me demande quelle influence ont les namespaces dans les requêtes XPath.

    Merci pour votre aide.
    Fichiers attachés Fichiers attachés
    (\ _ /)
    (='.'=)
    (")-(")

  2. #2
    Expert éminent
    Avatar de GrandFather
    Inscrit en
    Mai 2004
    Messages
    4 587
    Détails du profil
    Informations personnelles :
    Âge : 54

    Informations forums :
    Inscription : Mai 2004
    Messages : 4 587
    Points : 7 103
    Points
    7 103
    Par défaut
    Salut,

    XPath ne va pas t'être d'une grande utilité dans ce cas précis, utilise plutôt DOM : récupère l'élément edmx:ConceptualModels avec la méthode getElementsByTagNameNS(), puis ensuite parcours (récursivement ou séquentiellement) ses noeuds enfants listés par la méthode childNodes() .
    FAQ XML
    ------------
    « Le moyen le plus sûr de cacher aux autres les limites de son savoir est de ne jamais les dépasser »
    Giacomo Leopardi

  3. #3
    Membre expérimenté
    Avatar de FRED.G
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    1 032
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 1 032
    Points : 1 505
    Points
    1 505
    Par défaut
    Merci pour ta réponse !

    En fait la syntaxe XPath m'est imposée. Je voulais utiliser le fichier xml comme source d'une liaison (DataBinding) dans Windows Presentation Fundation au moyen d'un objet XmlDataProvider qui présente une propriété XPath permettant d'appliquer une requête "XPath" sour le fichier source.

    Merci quand même.
    (\ _ /)
    (='.'=)
    (")-(")

  4. #4
    Expert éminent
    Avatar de GrandFather
    Inscrit en
    Mai 2004
    Messages
    4 587
    Détails du profil
    Informations personnelles :
    Âge : 54

    Informations forums :
    Inscription : Mai 2004
    Messages : 4 587
    Points : 7 103
    Points
    7 103
    Par défaut
    Sans plus d'information sur la manière dont le provider va opérer le binding avec des données hiérarchiques, il est difficile d'établir ce qui doit être sélectionné et donc de définir une expression XPath... A tout hasard :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    //edmx:ConceptualModels/descendant::*
    Cela te renverra un ensemble de noeuds (nodeset) qui sont tous les éléments dont edmx:ConceptualModels est un ancêtre (dans l'ordre dans lequel ils apparaissent dans le document). Il faut aussi que tu trouves la propriété du XmlDataProvider qui permet d'indiquer que le préfixe edmx se rapporte à l'espace de noms http://schemas.microsoft.com/ado/2007/06/edmx.
    FAQ XML
    ------------
    « Le moyen le plus sûr de cacher aux autres les limites de son savoir est de ne jamais les dépasser »
    Giacomo Leopardi

  5. #5
    Membre expérimenté
    Avatar de FRED.G
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    1 032
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 1 032
    Points : 1 505
    Points
    1 505
    Par défaut
    J'ai renoncé pour l'instant à faire du Binding direct entre ma source XML et du WPF, mais j'y vois déjà un peu plus clair à propos des namepsace.

    Sinon pour parser et éditer mon fichier xml, j'ai préféré utiliser les API "Linq to Xml".

    Merci GF !

    FG.
    (\ _ /)
    (='.'=)
    (")-(")

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 17/06/2013, 10h45
  2. Réponses: 1
    Dernier message: 21/11/2011, 16h57
  3. Déclarations de variables pour tous les éléments d'un workbook
    Par kebab666 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 05/07/2007, 16h50
  4. [XSL] afficher tous les éléments fils d'un noeud
    Par alexandra dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 07/09/2006, 08h33
  5. Méthode pour supprimer tous les enfants d'un élément
    Par Pymm dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 10/05/2005, 12h10

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