Announcement

Collapse
No announcement yet.

In Need of some assistance from an XML / XSD developer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    In Need of some assistance from an XML / XSD developer

    OK, I am not a programmer but I poke around enough until I can either do something myself or can't. I'm a the can't point with this one but I'm not willing to give up on what I am trying to do yet, so I am turning to the community for some help.

    Goal: Use a script to parse the messages.xml file in the config directory so HSPhone message data can be loaded into devices for use in HSTouch.

    I can handle to getting data into devices, I just don't know anything about working with XML. I looked at some of the scripts out there but they don't seem to be working with schemas (XSD I believe). If I just needed to find a given node I think I could do what I need. It's working with a schema that seems to have made this complicated past my abilities.

    Can someone give me some pointers on writing some simple code to parse the messages.xml file and load into some variables in a script. I could take it from there. Here is what the messages.xml file looks like...

    HTML Code:
    <xml xmlns:s='uuid:XXXXXX-6DA3-11d1-A2A3-00AA00C14882'
    	xmlns:dt='uuid:XXXXXXXX-65B3-11d1-A29F-00AA00C14882'
    	xmlns:rs='urn:schemas-microsoft-com:rowset'
    	xmlns:z='#RowsetSchema'>
    <s:Schema id='RowsetSchema'>
    	<s:ElementType name='row' content='eltOnly' rs:updatable='true'>
    		<s:AttributeType name='CIDNumber' rs:number='1' rs:write='true'>
    			<s:datatype dt:type='string' dt:maxLength='4294967295' rs:precision='0' rs:long='true' rs:maybenull='false'/>
    		</s:AttributeType>
    		<s:AttributeType name='CIDName' rs:number='2' rs:write='true'>
    			<s:datatype dt:type='string' dt:maxLength='4294967295' rs:precision='0' rs:long='true' rs:maybenull='false'/>
    		</s:AttributeType>
    		<s:AttributeType name='FileName' rs:number='3' rs:write='true'>
    			<s:datatype dt:type='string' dt:maxLength='4294967295' rs:precision='0' rs:long='true' rs:maybenull='false'/>
    		</s:AttributeType>
    		<s:AttributeType name='HasBeenRead' rs:number='4' rs:write='true'>
    			<s:datatype dt:type='boolean' dt:maxLength='2' rs:precision='0' rs:fixedlength='true' rs:maybenull='false'/>
    		</s:AttributeType>
    		<s:AttributeType name='length' rs:number='5' rs:write='true'>
    			<s:datatype dt:type='i8' dt:maxLength='8' rs:precision='0' rs:fixedlength='true' rs:maybenull='false'/>
    		</s:AttributeType>
    		<s:AttributeType name='MailboxName' rs:number='6' rs:write='true'>
    			<s:datatype dt:type='string' dt:maxLength='4294967295' rs:precision='0' rs:long='true' rs:maybenull='false'/>
    		</s:AttributeType>
    		<s:AttributeType name='mdate' rs:number='7' rs:write='true'>
    			<s:datatype dt:type='dateTime' rs:dbtype='variantdate' dt:maxLength='16' rs:precision='0' rs:fixedlength='true'
    			 rs:maybenull='false'/>
    		</s:AttributeType>
    		<s:AttributeType name='tag' rs:number='8' rs:write='true'>
    			<s:datatype dt:type='int' dt:maxLength='4' rs:precision='0' rs:fixedlength='true' rs:maybenull='false'/>
    		</s:AttributeType>
    		<s:AttributeType name='LineNum' rs:number='9' rs:write='true'>
    			<s:datatype dt:type='int' dt:maxLength='4' rs:precision='0' rs:fixedlength='true' rs:maybenull='false'/>
    		</s:AttributeType>
    		<s:extends type='rs:rowbase'/>
    	</s:ElementType>
    </s:Schema>
    <rs:data>
    	<z:row CIDNumber='555555555' CIDName='Joe Smith' FileName='2010-07-29_10-08-45.wav' HasBeenRead='False'
    		 length='22' MailboxName='Default' mdate='2010-07-29T10:09:09' tag='3' LineNum='1'/>
    	
    </rs:data>
    </xml>
    Thanks in advance!

    FYI, I want to do this rather than the hsp.MBfirstunread() method as the message list is already there in the messages.xml file, sorted and also clearly identifies if the message was read or not (there is no hsp method to determine if a message is read or not).

    #2
    Which 'script' language are you writing this in: VB.Net or VBScript?
    Best regards,
    -Mark-

    If you're not out on the edge, you're taking up too much room!
    Interested in 3D maps? Check out my company site: Solid Terrain Modeling

    Comment


      #3
      Originally posted by mfisher View Post
      Which 'script' language are you writing this in: VB.Net or VBScript?
      Preferably vb.net

      Comment


        #4
        Here's some code to read the file and the elements attributes.

        Code:
        Try
                    Dim sXMLDoc As String = "X:\Program Files\HomeSeer 2\Config\messages.xml"
                    Dim m_xmld As XmlDocument
                    Dim m_nodelist As XmlNodeList
                    Dim m_node As XmlNode
        
                    'Create the XML Document
                    m_xmld = New XmlDocument()
        
                    'Load the Xml file
                    m_xmld.Load(sXMLDoc)
        
                    'Create an XmlNamespaceManager for resolving namespaces.
                    Dim nsmgr As New XmlNamespaceManager(m_xmld.NameTable)
                    nsmgr.AddNamespace("rs", "urn:schemas-microsoft-com:rowset")
                    nsmgr.AddNamespace("z", "#RowsetSchema")
        
                    'Get the list of name nodes 
                    m_nodelist = m_xmld.SelectNodes("xml/rs:data/z:row", nsmgr)
        
                    'Loop through the nodes
                    For Each m_node In m_nodelist
                        'Get the CIDNumber Attribute Value
                        Dim CIDNumber = m_node.Attributes.GetNamedItem("CIDNumber").Value
                        'Get the other Element Values
                        Dim CIDName = m_node.Attributes.GetNamedItem("CIDName").Value
                        Dim FileName = m_node.Attributes.GetNamedItem("FileName").Value
                        Dim HasBeenRead = m_node.Attributes.GetNamedItem("HasBeenRead").Value
                        Dim length = m_node.Attributes.GetNamedItem("length").Value
                        Dim MailboxName = m_node.Attributes.GetNamedItem("MailboxName").Value
                        Dim mdate = m_node.Attributes.GetNamedItem("mdate").Value
        
        
                        MessageBox.Show("CIDNumber: " & CIDNumber _
                          & " CIDName: " & CIDName & " FileName: " _
                          & FileName & " BeenRead: " & HasBeenRead _
                          & " Length: " & length & " MailboxName: " & _
                          MailboxName & " mdate: " & mdate)
        
                    Next
                Catch ex As Exception
                    'Error trapping
                    Debug.Print(ex.Message.ToString())
                End Try
        💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

        Comment


          #5
          Rupp, got an error right out of the gate:

          Script compile error: Type 'XmlDocument' is not defined.on line 17

          In other examples, I have seen the xml document declared as an Object. Maybe this has something to do with the error?

          Comment


            #6
            If you are running this via a HomeSeer script you will need to include the System.Xml file in your settings.ini file.

            ie ScriptingReferences=System.XML;System.XML.dll
            💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

            Comment


              #7
              Rupp, thanks for the timely reply and for the code. I never would have figured this out.

              I have gotten your script to work (although the debug.print line is thowing an error so I commented it out for now).

              Quick question, is there a way to go to a specific node (message) rather than going through each? Say I want to go to the first node but then run the script again and go to the next one?

              Thanks again for helping out!

              Comment


                #8
                Originally posted by heatvent View Post
                Rupp, thanks for the timely reply and for the code. I never would have figured this out.

                I have gotten your script to work (although the debug.print line is thowing an error so I commented it out for now).

                Quick question, is there a way to go to a specific node (message) rather than going through each? Say I want to go to the first node but then run the script again and go to the next one?

                Thanks again for helping out!
                There is but it would require a ton more code. The script itterates all the data so I'm not sure why you would want to run the script for each node. That would be redundant. What exactly are you trying to do?
                💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

                Comment


                  #9
                  Similar to the HSPhone web voicemail box, the current caller would be displayed in HSTouch. The way this will be done is to have a set of virtual devices (caller, number, etc.) that refresh in HSTouch. But only the current active message is displayed. So I would want to go to the next message or previous message, etc. I would need to go to specific node, load the info into the virtual devices and display in HSTouch. I'm sure I can figure out a different way, but is there at least a way to select a node by matching a string? I could use that to go to the caller I want.

                  Comment

                  Working...
                  X