XML to Rhino

Hi

I have geometric objects created and saved in an xml file from one piece of measurement software and I would like to use Python to parse the xml file so the geometric objects can be created in Rhino.
My first problem is that I am not a Python user, I have only used Rhinoscript since Rhino 1.0 so I need some guidance as to how I should proceed with this issue.
Secondly there seems to be a multitude of Python applications and approaches so again any advice will be gratefully received.

I have attached a typical xml file.

Thanks very much

RogerSteach.xml (76.3 KB)

Hi RogerD,

System.Xml and xpath is almost all you need to start:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino as rc
import clr

clr.AddReference("System.Xml")
from System.Xml import *

def extract_xml_points():
    xml_file = rs.OpenFileName("Please select xml-file to import points (steach.xml)")
    xml_doc = XmlDocument()
    xml_doc.Load(xml_file)
    point_nodes = xml_doc.SelectNodes("//RealPoint")
    for point_node in point_nodes:            
        x_node = point_node.SelectSingleNode("./x")        
        if x_node:
            x = x_node.InnerText
            y_node = point_node.SelectSingleNode("./y")
            if y_node:
                y = y_node.InnerText
                z_node = point_node.SelectSingleNode("./z")
                if z_node:
                    z = z_node.InnerText
                    #print "Adding point"                    
                    rs.AddPoint( map(float,(x,y,z)))
            
extract_xml_points()

I hope this helps.

Best regards,
Philip

Hi Philip

Many thanks for this I really appreciate it, I am still reading up on indentation and formatting of the data so this will really help having a live script to help me get my head round python.

Kind regards

RogerD