Question

I've been trying to get out width and height out of this xml:

<?xml version="1.0" encoding="utf-8"?>
<Collection MaxLevel="7" TileSize="256" Format="png" NextItemId="1" ServerFormat="Default" xmlns="http://schemas.microsoft.com/deepzoom/2009">
  <Items>
    <I Id="0" N="0" Source="157_images/16.XML">
      <Size Width="1200" Height="900" />
      <Viewport Width="1" X="0" Y="0" />
    </I>
  </Items>
</Collection>

but it was impossible, the xml itself doesnt look like other xml files i worked with the code I have so far is:

    path = "157.xml"
    Dim document = XDocument.Load(Server.MapPath(path))
    Dim Xml As String = document.ToString
    Dim myallelements As XElement = XElement.Parse(Xml)
Was it helpful?

Solution

This clumsy syntax incorporates the default namespace:

 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim path As String = "C:\test\157.xml"
    Dim n As XmlNode
    Dim xm As New XmlDocument

    Dim nsmgr As New XmlNamespaceManager(xm.NameTable)
    nsmgr.AddNamespace("q", "http://schemas.microsoft.com/deepzoom/2009")

    xm.Load(path)
    n = xm.SelectSingleNode("/q:Collection/q:Items/q:I/q:Size", nsmgr)

    Debug.Print("width = " & n.Attributes("Width").Value & "  height = " & n.Attributes("Height").Value)

End Sub

OTHER TIPS

 Dim size = myallelements...<Collection>...<Items>...<I>...<Size>
 Dim width = size.@Width.Value
 Dim Height = size.@Height
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top