1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[RESOLVIDO] Progress vs. XML

Discussão em 'EMS , HCM e Totvs 11' iniciado por hugo_mlcabral1, Junho 6, 2017.

Status do Tópico:
Não esta aberto para novas mensagens.
  1. hugo_mlcabral1

    hugo_mlcabral1 Sem Pontuação

    Senhores, bom dia!

    Alguém tem algum material de como manipular(criar, ler, alterar...) XML no progress?
  2. bootstrapmaster

    bootstrapmaster Moderator Moderador Equipe de Suporte

    Eu achei mais complicado usar as funções de xml, que vc fica passeando pelos NODES da vida, do que ler ele como um TXT e eu mesmo localizar as TAGs e fazer o trabalho, mas ....

    Código:
    How to create an XML document in 4GL / ABL using DOM
    Environment  Product: OpenEdge
    Version: 10.x, 11.x
    Product: Progress
    Version: 9.1E
    OS: All Supported platforms
    Other: N/A 
    Question/Problem Description  How to create an XML document in 4GL / ABL using DOM
    How to create an XML document from a Progress OpenEdge database
    Example code using X-DOCUMENT and X-NODEREF object types to create an XML document
    Clarifying Information  
    Error Message  
    Defect/Enhancement Number  
    Cause  
    Resolution  The following code illustrates a typical way to use to use ABL support for the Document Object Model (DOM) API, to create an XML document from data in an OpenEdge database.
    
    This creates an XML document with three main nodes. The first two contain arbitrary text to show how to build any node necessary using ABL statements. The second of the two shows how nodes can be nested in a parent-child relationship. The third main node contains data extracted from the first record in the Customer table of the Sports2000 sample database shipped with OpenEdge.
    
    DEFINE VARIABLE hDoc AS HANDLE.
    DEFINE VARIABLE hRoot AS HANDLE.
    DEFINE VARIABLE hRow AS HANDLE.
    DEFINE VARIABLE hField AS HANDLE.
    DEFINE VARIABLE hText AS HANDLE.
    DEFINE VARIABLE hBuf AS HANDLE.
    DEFINE VARIABLE hDBFld AS HANDLE.
    DEFINE VARIABLE i AS INTEGER.
    CREATE X-DOCUMENT hDoc. /* XML document handle */
    CREATE X-NODEREF hRoot. /* root node handle */
    CREATE X-NODEREF hRow. /* handle for DB table rows & misc non-DB nodes */
    CREATE X-NODEREF hField. /* handle for DB fields & non-DB nested nodes*/
    CREATE X-NODEREF hText. /* handle for text nodes */
    /*set up a root node*/
    hDoc:CREATE-NODE(hRoot,"Datagram","ELEMENT").
    hDoc:APPEND-CHILD(hRoot).
    hRoot:SET-ATTRIBUTE("xmlns","").
    /* For each node below the root: */
    /* 1. Create an element node. */
    /* 2. Attach it to the root. */
    /* 3. Create a text node for it. */
    /* 4. Link the text node to the element node. */
    /* 5. Fill in the text. */
    /* hard-code nodes that don't come from the OpenEdge database */
    /* Example: "MessageId" node */
    hDoc:CREATE-NODE(hRow,"MessageID","ELEMENT").
    hRoot:APPEND-CHILD(hRow).
    hDoc:CREATE-NODE(hText, "", "TEXT").
    hRow:APPEND-CHILD(hText).
    hText:NODE-VALUE = "8a58f0b1-7e27-415c-b4f1-c87ab0a02084".
    /* Example: Passport node has children linked to it in a nested fashion */
    hDoc:CREATE-NODE(hRow,"Passport","ELEMENT").
    hRoot:APPEND-CHILD(hRow).
    hDoc:CREATE-NODE(hField, "Node", "ELEMENT").
    hRow:APPEND-CHILD(hField).
    hDoc:CREATE-NODE(hText, "", "TEXT").
    hField:APPEND-CHILD(hText).
    hText:NODE-VALUE = "http://www.mycompany.com/cis".
    hDoc:CREATE-NODE(hField, "SecurityKey", "ELEMENT").
    hRow:APPEND-CHILD(hField).
    /* Example: "Document" node using the fields in the sports2000 Customer table */
    hBuf = BUFFER customer:HANDLE.
    FIND FIRST customer NO-LOCK. /* just one for demonstration */
    hDoc:CREATE-NODE(hRow,"Document","ELEMENT"). /*create a row node*/
    hRoot:APPEND-CHILD(hRow). /*put the row in the tree*/
    /*Add the fields as tags in the xml*/
    REPEAT i = 1 TO hBuf:NUM-FIELDS:
    hDBFld = hBuf:BUFFER-FIELD(i).
    /*create a tag with the field name*/
    hDoc:CREATE-NODE(hField, hDBFld:NAME, "ELEMENT").
    /*put the new field as next child of row. */
    hRow:APPEND-CHILD(hField).
    /* If field has unknown value, just leave the tag empty */
    IF hDBFld:BUFFER-VALUE = ? THEN NEXT.
    /* Add a node to hold field value. Text nodes don't get a name. */
    hDoc:CREATE-NODE(hText, "", "TEXT").
    hText:NODE-VALUE = STRING(hDBFld:BUFFER-VALUE).
    /*attach the text to the field*/
    hField:APPEND-CHILD(hText).
    END.
    /*write the XML node tree to an xml file*/
    hDoc:SAVE("file","myfile.xml").
    DELETE OBJECT hDoc.
    DELETE OBJECT hRoot.
    DELETE OBJECT hRow.
    DELETE OBJECT hField.
    DELETE OBJECT hText.
    
    Workaround  
    Notes  ABL also provides support for reading and writing XML using the SAX API, as well as special features to read and write XML using temp-tables and ProDataSets.
    
    References to Other Documentation:
    
    OpenEdge Development: Working with XML
    Attachment    
    
    Isso que está no KBASE
    hugo_mlcabral1 curtiu isso.
  3. bootstrapmaster

    bootstrapmaster Moderator Moderador Equipe de Suporte

    Hein, dei uma olhada no SAX API, parece interessante e bem mais simples, eu vou investigar melhor, mas pelo que eu percebi, é esse recurso que a totvs usar pra gerar o xml da nota fiscal, onde valida os seus dados contra um XSD antes de criar o XML.
  4. hugo_mlcabral1

    hugo_mlcabral1 Sem Pontuação

    Massa vou dar uma olhada valeu @bootstrapmaster
Status do Tópico:
Não esta aberto para novas mensagens.

Compartilhe esta Página