locked
Read xml file and sort data by child value RRS feed

  • Question

  • Yitzhak Khabinsky help me with starting to read an xml file and based on his input I discovered more about the xml file what what needs to be read.

    The xml file is very large and I'm not sure how to post it well formed.

    Here is the heading of the file.

    <?xml version="1.0" encoding="utf-8" standalone="no" ?>
    <BOMLayouts Version="1">

      <MergeSettings Enabled="1"/>

      <AutoBestFit Enabled="1"/>

      <Layout Index="0">
        <XtraSerializer application="TreeListBlockSelector" version="1.0">
          <property name="#LayoutVersion"/>
          <property name="#LayoutScaleFactor">@1,Width=1@1,Height=1</property>
          <property isnull="true" name="AutoFillColumn"/>
          <property name="AutoFillFieldName"/>
          <property isnull="true" name="HierarchyColumn"/>
          <property name="HierarchyFieldName"/>
          <property name="TreeViewFieldName"/>
          <property isnull="true" name="TreeViewColumn"/>
          <property name="ViewStyle">Default</property>
          <property name="ImageIndexFieldName">ImageIndex</property>
          <property name="KeyFieldName">ID</property>
          <property name="ParentFieldName">ParentID</property>
          <property name="ChildListFieldName"/>
          <property name="PreviewFieldName"/>
          <property name="CheckBoxFieldName"/>
          <property iskey="true" isnull="true" name="OptionsView">
            <property name="BestFitNodes">Visible</property>
            <property name="AutoWidth">false</property>
            <property name="FocusRectStyle">RowFullFocus</property>
      </property>
          <property iskey="true" isnull="true" name="OptionsSelection">
            <property name="KeepSelectedOnClick">false</property>
            <property name="EnableAppearanceFocusedRow">false</property>
            <property name="EnableAppearanceFocusedCell">false</property>
      </property>

    There seems to be three sections to the file:

    <Layout Index="0"> & <Layout Index="1"> & <Layout Index="2">

    I need to focus on <Layout Index="1">

    Here is information on what is necessary.

      </property>
          <property name="BorderStyle">Default</property>
          <property name="ShowButtonMode">ShowOnlyInEditor</property>
          <property name="IndicatorWidth">12</property>
          <property name="PreviewLineCount">1</property>
          <property name="RowHeight">80</property>
          <property name="ColumnPanelRowHeight">-1</property>
          <property name="BandPanelRowHeight">-1</property>
          <property name="FooterPanelHeight">-1</property>
          <property name="HorzScrollVisibility">Auto</property>
          <property name="HorzScrollStep">3</property>
          <property name="VertScrollVisibility">Auto</property>
          <property name="CustomizationFormBounds">@4,X=1616@3,Y=634@3,Width=266@3,Height=223</property>
          <property iskey="true" name="Columns" value="44">
            <property iskey="true" isnull="true" name="Item1">
              <property name="ImageIndex">-1</property>
              <property name="ImageAlignment">Near</property>
              <property name="Caption">Item</property>
              <property name="ToolTip"/>
              <property name="CustomizationCaption"/>
              <property name="FieldName">Item Order</property>
              <property name="FieldNameSort"/>
              <property name="Name">treeListItem Order</property>
              <property name="AllowIncrementalSearch">true</property>
              <property name="Fixed">None</property>
              <property name="ColumnEditName"/>
              <property name="ShowButtonMode">Default</property>
              <property name="VisibleIndex">0</property>
              <property name="Visible">true</property>
              <property name="SortOrder">None</property>
              <property name="SortIndex">-1</property>
              <property name="SortMode">Custom</property>
              <property name="FilterMode">Value</property>
              <property name="ShowUnboundExpressionMenu">false</property>
              <property iskey="true" isnull="true" name="Format">
                <property name="FormatString"/>
                <property name="FormatType">None</property>
          </property>

    I need to create an array listing the Captions of items that are visible and in ascending order based on Visible Index. 

    I can upload xml file if necessary.

    Friday, August 7, 2020 5:09 PM

All replies

  • Try something like this:

    Dim xdoc = New XmlDocument
    xdoc.Load("C:\MyFile.xml")
    
    Dim array As String() = xdoc.SelectNodes("//Layout[@Index=1]//property[property[@name='Visible' and .='true']][property[@name='Caption']][property[@name='VisibleIndex' and number(.)]]") _
       .Cast(Of XmlNode) _
       .Select(Function(n) New With {.Caption = n.SelectSingleNode("property[@name='Caption']").InnerText.Trim, .VisibleIndex = CInt(n.SelectSingleNode("property[@name='VisibleIndex']").InnerText)}) _
       .OrderBy(Function(d) d.VisibleIndex) _
       .Select(Function(d) d.Caption) _
       .ToArray

    Or show your real file. If it is too large, you can publish it on your OneDrive account, or similar, maybe compress, and give a link.


    Friday, August 7, 2020 7:54 PM