Results 1 to 10 of 26

Thread: xml

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Location
    Colombia
    Posts
    2,509

    Default xml

    hi all
    I feel some shame asking for help on this issue. I am trying to read an xml file and take it to a structure, but I am somewhat entangled to move in the child nodes.
    I appreciate your help

    Edgar


    Code:
     Procedure ShowInformation Integer hoNode Integer iLineCount
            String sName sProducto sPrf sTel sMail sWEBSITE spsText sATMOSPHERE sSTREET
            String sTELEPHONE
            Integer iType iChildren
            Handle hoNextNode
            // If the node is an element (e.g. Customer), get the element's nodename and the attribute value for NAME
            // skip all non-element nodes
            Get piNodeType of hoNode to iType
            If (iType = NODE_ELEMENT) Begin
               Get psPrefix   of hoNode to sPrf
               Get psBaseName  of hoNode to sName
              // Get NamedNode sName to HandleVariable
                 
               Get AttributeValue of hoNode "Customer-Id" to sName
               Get AttributeValue of hoNode "Customer/Name" to sProducto
               Get AttributeValue of hoNode "Telephone" to sWEBSITE
               Get ChildNodeValue of hoNode "Customer/Telephone" to sTELEPHONE
              // Get ChildNodeValue of hoNode "ADDRESS/STREET" to sSTREET
               Showln iLineCount ": Node is [" (psNodeName(hoNode)) "] Name is [" sName "]" " Producto:" sProducto
               get child_count of hoNode to iChildren
               if (iChildren) Send Info_Box iChildren
    
               Get FirstChild of hoNode to hoNextNode // get the first node
               While (hoNextNode<>0)
                 Get AttributeValue  of hoNextNode "Name" to sName
                 //Get NextNode of hoNextNode to hoNextNode
             //     Get psText of hoNextNode to  spsText
             //     Get psPrefix    of hoNextNode to sPrf
             //     Get psBaseName  of hoNextNode to sName
             //     Get psNodeName     of hoNextNode "NAME"     to sName
             //     Get ChildNodeValue of hoNextNode "NAME"     to sName
             //     Get ChildNodeValue of hoNextNode "TELEPHONE" to sTel
             //     Get ChildNodeValue of hoNextNode "EMAIL"    to sMail
             //     
             //     Get NextSibling of hoNextNode to hoNextNode // now get next sibling node
             //     
             //   //  Send Destroy of hoNode     // Important: get rid of the previous node object
             //   //  Move hoNextNode to hoNode
               Loop
               
              
        //    Get FirstChild oF hoNode to hoNextNode
        //    Get piNodeType of hoNode to iType
        // 
        //    If (iType = NODE_ELEMENT) Begin
        //        Get AttributeValue of hoNextNode "NAME" to sName    
        //    End
        ///     Get AttributeValue of hoNextNode "PRODUCT" to sProducto
             // Showln iLineCount sName (psNodeName(hoNextNode)) "] Name is [" sName "]" 
    
            End
        End_Procedure
     
        Procedure Test
            Integer bOk i            // Boolean to test return value.
            Integer hoXML            // Handle to XML Document object
            Integer hoRoot           // Handle to root node of document.
            Integer hoNode           // handle to a node for testing
            Integer hoNextNode       // used to find the previous node
            Integer iLineCount hoList iItems
            String sDataPath sNamespace
            Handle hoCust
            
             Get psDataPath of (phoWorkspace(ghoApplication)) to sDataPath         
             Get PathAtIndex of (phoWorkspace(ghoApplication)) sDataPath 1 to sDataPath
                
            // Create document object
         //    Get psDataPath of cu to sDataPath
             Append sDataPath "\myCustomer.xml"
            Get Create (RefClass(cXmlDomDocument)) to hoXML
           // Move "http://www.dataaccess.com/Customers" to sNamespace  
                
                // psSelectionNamespaces must contain a prefix for each namespace it stores
                // This has to be set in order to use FindNode and FindNodeList
           /// Set psSelectionNamespaces of hoXML to ("xmlns:cust='" - sNamespace - "'")  
                
            Set psDocumentName of hoXML to sDataPath //".\NewCustomer.xml"
            
            
            // Turn on the xml parse test so errors are reported.
            Set pbAsync of hoXML to False
            Set pbValidateOnParse of hoXML to True
     
      
            // Load the document
            Get LoadXMLDocument of hoXml to bOK
     
            // If the document fails to load, abort the program
            If nOT bOK begin
                Send BasicParseErrorReport of hoXml
                Send Destroy of hoXML
                Procedure_Return
            End
     
            // Search from the root.
            Get DocumentElement of hoXml to hoRoot
            if (hoRoot=0) Begin
                Error 10001 "Cannot get the root node for the XML document test.xml"
                Send Destroy of hoXml
                Procedure_Return
            End
         //  Get FindNodeList of hoRoot "CUSTOMER" to hoList
         //  Get NodeListLength of hoList to iItems
         //  Decrement iItems
         //  For i from 0 to iItems
         //      Get CollectionNode of hoList i to hoCust
         //      Send ShowCust hoCust
         //
         //      Send Destroy of hoCust
         //  Loop
     
            // traverse through nodes. Start with first child and then
            // move through each sibling
          Move 0 to iLineCount
          Get FirstChild of hoRoot to hoNode // get the first node
          While (hoNode<>0)
              Increment iLineCount
              Send ShowInformation hoNode iLineCount
              Get NextNode of hoNode to hoNode // now get next sibling node, destroy current node
          Loop
       
            Send Destroy of hoRoot
            Send Destroy of hoXml
     
        End_Procedure
    Attached Files Attached Files

Posting Permissions

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