Results 1 to 4 of 4

Thread: Missing XML Name Information???

  1. #1

    Thread Starter
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    Missing XML Name Information???

    I've put together the following code that reads an XML file into an XML Document, and iterating thru each node in the document, I'm placeing the node's name and associated value into a treeview:

    VB Code:
    1. Private Sub Button1_Click_1 (ByVal sender As System.Object, ByVal e As System.EventArgs) _[i]edit[/i]
    2. Handles Button1.Click
    3.     Dim MyBoo As Boolean
    4.     Dim MyNode As XmlNode
    5.     Dim FitN As TreeNode
    6.     Dim rootNode As TreeNode
    7.     Dim MyStockXML As New Xml.XmlDocument()
    8.     MyStockXML.Load ("c:\psip_stocklibrary.xml")
    9.     TreeView1.Visible = False
    10.     Application.DoEvents()
    11.     rootNode = TreeView1.Nodes.Add("Media")
    12.     TreeView1.SelectedNode = rootNode
    13.     Call FILLTreeV(MyStockXML, rootNode)
    14.     TreeView1.Visible = True
    15. End Sub
    16. Public Sub FILLTreeV(ByVal mNode As XmlNode, ByVal pNode As TreeNode)
    17.     Dim FitN As TreeNode
    18.     Dim selNode As TreeNode
    19.     Dim MyChildNode As XmlNode
    20.     For Each MyChildNode In mNode '.ChildNodes
    21.         FitN = New TreeNode(MyChildNode.Name & " " & MyChildNode.Value)
    22.         pNode.Nodes.Add (FitN)
    23.         If MyChildNode.HasChildNodes = True Then
    24.             FILLTreeV(MyChildNode, FitN)
    25.         End If
    26.     Next
    27. End Sub

    Now, the XML text in the file "c:\psip_stocklibrary.xml" looks like:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <stockLibrary xmlns="http://www.xerox.com/psip/app/media/StockLibrary" _edit
    xmlns:vudu="vudu" vudu:class="psip.app.media.xml.StockLibraryFormat" _edit
    vudu:serial="-1141390230395564101_0.2.1">
      <nextStockID value="376" />
      <media>
        <name>(p005426_19p5x14p33)</name>
        <predefinedColor>MEDIA_COLOR_WHITE</predefinedColor>
        <weight>280</weight>
        <sidesCoated>0</sidesCoated>
        <coatingType>MEDIA_COATING_TYPE_NONE</coatingType>
        <thickness>334</thickness>
        <finish>MEDIA_FINISH_REGULAR</finish>
        <xeroxDefined>false</xeroxDefined>
        <rmlVersion />
        <comments></comments>
        <hidden>false</hidden>
    yadayadayada...
    And my resulting treeview looks like this:



    So what I don't understand is:

    the first node below the root is named xml version="1.0" encoding="UTF-8" which is seen in the file as:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>

    The next node, seen as stock Library in the picture, has as its text in the file:

    Code:
    <stockLibrary xmlns="http://www.xerox.com/psip/app/media/StockLibrary" _edit
    xmlns:vudu="vudu" vudu:class="psip.app.media.xml.StockLibraryFormat" _edit
    vudu:serial="-1141390230395564101_0.2.1">
    and the third node, seen as nextStockID, has the following text line in the file:

    Code:
    <nextStockID value="376" />
    So:
    [list=a][*]What happened to the bracketing question marks in the first treeview node?[*]Why is the second node only named stockLibrary? What happened to all of that http and vudu info as seen in its file line?[*]Whats up with that value="376" in the file for nextStockID? Why doesn't it show up in the TreeView?[*]The node that is called "name" contains a subnode identified as #text (p005426_19p5x14p33). Isn't that SubNode supposed to be the Value of the name node {minus the #text bit}, since its structure in the file is: <name>(p005426_19p5x14p33)</name> ??? [/list=a]


    -Lou
    Attached Images Attached Images  

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    If you want to display the attributes, your going to need to iterate through the collection for each node. Also, you won't have to worry about recursion, since attributes cannot have child attributes.

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Also Value and InnerText are not the same thing and since you are using Value then a node like this <node>text</node> will give you #text text while the InnerText property will return text. Also the first node is a different kind of node, a processor directive (i think thats the name).

  4. #4

    Thread Starter
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    Thanks Lethal & Edneeis!

    With your observations, it led me to update my code to this:

    VB Code:
    1. Public Sub FILLTreeV(ByVal mNode As XmlNode, ByVal pNode As TreeNode)
    2.     Dim MyI As Long
    3.     Dim MyAtr As Xml.XmlAttribute
    4.     Dim FitN As TreeNode
    5.     Dim selNode As TreeNode
    6.     Dim MyChildNode As XmlNode
    7.     Dim MyOutName As String
    8.     For Each MyChildNode In mNode '.ChildNodes
    9.         MyOutName = MyChildNode.Name & " " & MyChildNode.Value
    10.         If Not MyChildNode.Attributes Is Nothing Then
    11.             For Each MyAtr In MyChildNode.Attributes
    12.                 MyOutName = MyOutName & " " & MyAtr.Name & "=" & MyAtr.Value
    13.             Next
    14.             MyOutName = Trim(MyOutName)
    15.         End If
    16.         FitN = New TreeNode(MyOutName)
    17.         pNode.Nodes.Add (FitN)
    18.         If MyChildNode.HasChildNodes = True Then
    19.             FILLTreeV(MyChildNode, FitN)
    20.         End If
    21.     Next
    22. End Sub

    Which produces my desired output:



    When I have a chance, I'll build on the innertext suggestion.

    Thanks Again!

    -Lou
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width