locked
read xml RRS feed

  • Question

  • User1610800555 posted

    hi

    i need to read the xml in the string variable. the "item" can be inside main node and can be inside sub nodes. 

    i need to read direct child nodes(item) only. i don't want to read all item node at one time.

    Thursday, November 6, 2014 3:22 AM

Answers

  • User1610800555 posted

    i had find the solution

    i can get the root node using the following code

    Dim po As XDocument = XDocument.Load("PurchaseOrders.xml")
    
    ' LINQ to XML query
    Dim el1 As XElement = po.Root
    
    ' XPath expression
    Dim el2 As XElement = po.XPathSelectElement("/PurchaseOrders")
    
    If el1 Is el2 Then
        Console.WriteLine("Results are identical")
    Else
        Console.WriteLine("Results differ")
    End If
    Console.WriteLine(el1.Name)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 13, 2014 2:43 AM

All replies

  • User-1516073966 posted

    Hi

    Can you post the xml and what is that you want to read from xml as well. From your post I understand an element with name "item" will be inside a root nod and "item" element have sub elements/nodes which are also "item". Can you see the following xml and confirm is this what your xml looks like.

    <item Property="Computer" >
     <item Property="Manufacturer" Value="LENOVO" />
     <item Property="Family" Value="Not Available" />
     <item Property="Product Name" Value="10A9000TAU" />
     <item Property="Model" Value="10A9000TAU" />
     <item Property="Version" Value="ThinkCentre M93p" />
     <item Property="Serial Number" Value="PB000400" />
     <item Property="SMBIOS Asset Tag" Value="Not Available" />
     <item Property="SKU Number" Value="Lenovo" />
     <item Property="Chassis" Value="Not Available" />
     <item Property="PC System Type" Value="Desktop" />
     <item Property="Machine Type" Value="AT/AT COMPATIBLE" />
     <item Property="Firmware Type" Value="BIOS" />
     <item Property="Infrared (IR) Supported" Value="No" />
     <item Property="UUID" Value="123456789" />
    </item>

    Thursday, November 6, 2014 4:25 AM
  • User1610800555 posted
      <items>
                <item>
                    <label>abc</label>
                    <width>100</width>
                </item>
                <item>
                    <label>def</label>
                    <width>100</width>
                </item>
                <item>
                    <table>
                        <row>
                            <cell>
                                <item></item>
                            </cell>
                            <cell>
                                <item></item>
                            </cell>
                        </row>
                    </table>
                </item>
                <item>
                    <tabs>
                        <tab>tab1</tab>
                    </tabs>
                    <pages>
                        <item></item>
                        <item></item>
                    </pages>
                </item>
            </items>

    i need to read the item containers inside list, table, list and sub list into xml . use that xml i need to dynamically create controls. i don't know they do in sharepoint form designer.

    In the sharepoint form designer we can drag and drop the items, tables and tabs to crate custom form.

    hope you understand my problem.

    Thursday, November 6, 2014 4:36 AM
  • User1508394307 posted

    i need to read the item containers inside lis

    What it the exact issue?

    To read you can simply use

    XDocument d = XDocument.Load(new StringReader("your xml here"));
                var items = from y in d.Descendants("item") 
                            select y;
    foreach (var i in items)
        Console.WriteLine(i);

    There is a lot of information regarding this matter, just try to search this forum or google.

    Friday, November 7, 2014 4:34 PM
  • User-1516073966 posted

    Hi

    You wanted to read the child elements from the "item" node?

    e.g: Considering the first element which has label and width you wanted to read those.  Is that correct?

    Monday, November 10, 2014 3:16 AM
  • User1610800555 posted

    i have posted the xml format 

    i need to read direct item child node from items node i don't want to read sub sub item nodes

    Thursday, November 13, 2014 2:00 AM
  • User1610800555 posted

    i had find the solution

    i can get the root node using the following code

    Dim po As XDocument = XDocument.Load("PurchaseOrders.xml")
    
    ' LINQ to XML query
    Dim el1 As XElement = po.Root
    
    ' XPath expression
    Dim el2 As XElement = po.XPathSelectElement("/PurchaseOrders")
    
    If el1 Is el2 Then
        Console.WriteLine("Results are identical")
    Else
        Console.WriteLine("Results differ")
    End If
    Console.WriteLine(el1.Name)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 13, 2014 2:43 AM
  • User1610800555 posted

    if i use smirnov code it will return all item nodes inside the xml

    i want to get only direct  item child nodes

    Friday, November 14, 2014 11:35 PM