importar (filtrar) nodos xml por nombre de nodo

Un usuario Pregunto ✅

hgorina

Tengo varios archivos XML con una variedad de datos almacenados en ellos.

necesito crear tablas basadas en los nombres de los nodos. Los datos contenidos en diferentes nodos del archivo XML son bastante diferentes

aquí hay un ejemplo de datos:

<BIMListDS xmlns="http://tempuri.org/BIMListDS.xsd">
  <DatabaseInfo>
    <ID>a71e1eb0-9811-448c-952c-c5f99d197bfd</ID>
    <SchemaVersion>3</SchemaVersion>
    <Name>01 PW Imperial 2016</Name>
    <LastUpdatedDate>2016-05-24T14:29:06.8645433</LastUpdatedDate>
    <IsRemote>true</IsRemote>
    <RemoteServerAddress>net.tcp://PW02BIMList:5055/BIMListDataService</RemoteServerAddress>
    <IsCloud>false</IsCloud>
    <CreatedBy>46d418f4-a599-44ee-9a12-72a39b123d20</CreatedBy>
    <LastUpdateBy>5ad2d00c-e4d7-4c64-8d01-2a410940b9e2</LastUpdateBy>
  </DatabaseInfo>
  <User>
    <ID>46d418f4-a599-44ee-9a12-72a39b123d20</ID>
    <Name>gorinah</Name>
  </User>
  <User>
    <ID>5ad2d00c-e4d7-4c64-8d01-2a410940b9e2</ID>
    <Name>gorina_admin</Name>
  </User>
  <User>
    <ID>cd195d56-5603-4d97-a38f-baeecc3be4a0</ID>
    <Name>lopezb</Name>
  </User>
  <User>
    <ID>58c53056-67e8-41ac-980d-d75586b12c13</ID>
    <Name>moorej</Name>
  </User>
  <User>
    <ID>d269e3ba-163e-4903-8cba-07c520dc0046</ID>
    <Name>clinea</Name>
  </User>
  <User>
    <ID>c26b59d7-bb5b-4213-a8d6-06cc89c7c7a8</ID>
    <Name>hamiltonad</Name>
  </User>
 <ContentItem>
    <ID>22389006-df18-419f-a657-d005bb31d642</ID>
    <Name>Graphic-Cross</Name>
    <CategoryID>-2000279</CategoryID>
    <Path>S:_FirmwideBIMListContent2016-Imperial_Hatches(RVT).rvt</Path>
    <IsFamily>false</IsFamily>
    <IsVisible>true</IsVisible>
    <AverageRating>0</AverageRating>
    <TotalLoadCount>0</TotalLoadCount>
    <AddedBy>5ad2d00c-e4d7-4c64-8d01-2a410940b9e2</AddedBy>
    <LastUpdatedBy>5ad2d00c-e4d7-4c64-8d01-2a410940b9e2</LastUpdatedBy>
    <AddedDate>2016-05-09T11:57:38.3246744-05:00</AddedDate>
    <LastUpdatedDate>2016-05-09T11:57:38.3246744-05:00</LastUpdatedDate>
    <ElementId>3215</ElementId>
    <IsOffline>false</IsOffline>
  </ContentItem>
  <ContentItem>
    <ID>d36f216f-6989-4417-8668-9c52dfc923ec</ID>
    <Name>Graphic-Crosshatch - Large</Name>
    <CategoryID>-2000279</CategoryID>
    <Path>S:_FirmwideBIMListContent2016-Imperial_Hatches(RVT).rvt</Path>
    <IsFamily>false</IsFamily>
    <IsVisible>true</IsVisible>
    <AverageRating>0</AverageRating>
    <TotalLoadCount>0</TotalLoadCount>
    <AddedBy>5ad2d00c-e4d7-4c64-8d01-2a410940b9e2</AddedBy>
    <LastUpdatedBy>5ad2d00c-e4d7-4c64-8d01-2a410940b9e2</LastUpdatedBy>
    <AddedDate>2016-05-09T11:57:43.9126149-05:00</AddedDate>
    <LastUpdatedDate>2016-05-09T11:57:43.9126149-05:00</LastUpdatedDate>
    <ElementId>3231</ElementId>
    <IsOffline>false</IsOffline>
  </ContentItem>

Necesito crear tablas basadas en los nombres de los nodos. el número de nodos de cada tipo varía

He seguido las instrucciones de la siguiente publicación: http://community.powerbi.com/t5/Desktop/Import-multiple-XML-files/mp/8900/highlight/true#M1596

ayudó mucho, gracias!

sin embargo, necesito seleccionar solo algunos tipos de nodos y quiero basarlo en el nombre

la función

(path as text) =>
let
    Source = Xml.Tables(File.Contents(path)),
    Table0 = Source{0}[Table],
    #"Changed Type" = Table.TransformColumnTypes(Table0,{{"ID", type text}, {"SchemaVersion", Int64.Type}, {"Name", type text}, {"LastUpdatedDate", type datetime}, {"IsRemote", type logical}, {"RemoteServerAddress", type text}, {"IsCloud", type logical}})
in
    #"Changed Type"

me permite recorrer el archivo xml y obtener las tablas secuencialmente, pero estoy tratando de seleccionar solo los nodos que me interesan.

muchas gracias por su ayuda

@hgorina

No estoy muy seguro de su requisito, si desea cargar la tabla de elementos por nombre pero no secuencialmente (0,1,2, etc.), puede intentar

let
    Source = Xml.Tables(File.Contents("C:Usersuser1Desktop1.XML")),
    Table2 = Source{[Name="User"]}[Table]
in
    Table2

Captura.PNG

@hgorina

No estoy muy seguro de su requisito, si desea cargar la tabla de elementos por nombre pero no secuencialmente (0,1,2, etc.), puede intentar

let
    Source = Xml.Tables(File.Contents("C:Usersuser1Desktop1.XML")),
    Table2 = Source{[Name="User"]}[Table]
in
    Table2

Captura.PNG

hgorina

En respuesta a Eric_Zhang

¡Gracias!

Funcionó.

tal vez necesito aclarar la tarea:

en varios XML con los que estoy trabajando, existen algunas tablas en todos ellos y algunas tablas existen solo en algunos XML. Además, el orden de secuencia de las tablas no es el mismo en algunas de ellas. por eso fue omportante sacarlos por nombre

muchas gracias de nuevo:)

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *