Multiple XML Paths

Answered

Comments

2 comments

  • 2
    Comment actions Permalink
    Avatar
    Jonas Seemann

    For the people who are interested in the solution:

    When defining "Passing", dont use single quotes. It is not a string, but a object you want to define.

    Furthermore, when declaring a XML path, don't write

    "link_data" XML PATH 'link_data'

    but

    "link_data" XML PATH '.'

    The path of the table is defined in the next XMLTable

     XMLTABLE('/link_data' PASSING '"o"."link_data"'

    In conclusion the full and correct code is this:

     

    SELECT 
    "x.idColumn",
    "x.account_id",
    "x.name",
    "x.id",
    "x.body",
    "x.object_type",

    "o.page_id",
    "o.instagram_actor_id",

    "l.link",
    "l.message",
    "l.attachment_style",
    "l.call_to_action",

    "c.link",
    "c.image_hash",
    "c.name",
    "c.description",
    "c.type"
    FROM
    (exec "Facebook".invokeHTTP(endpoint=>'https://graph.facebook.com/v3.0/CREATIVEID/adcreatives?fields=account_id,name,object_id,id,body,object_story_spec,object_type,effective_object_story_id,link_url,object_url',action=>'GET',requestContentType=>'application/json')) w,
    XMLTABLE(XMLNAMESPACES( 'http://www.w3.org/2001/XMLSchema-instance' as "xsi" ),'/root/data' PASSING JSONTOXML('root',to_chars(w.result,'UTF-8'))
        COLUMNS
        "idColumn" FOR ORDINALITY,
        "account_id" STRING  PATH 'account_id',
        "name" STRING  PATH 'name',
        "id" STRING  PATH 'id',
        "body" STRING  PATH 'body',
        "object_type" STRING  PATH 'object_type',
        "object_story_spec" XML PATH '.')
        "x",
        XMLTABLE('object_story_spec' PASSING "x"."object_story_spec"
        COLUMNS
        "page_id" STRING  PATH 'page_id',
        "instagram_actor_id" STRING  PATH 'instagram_actor_id',
        "link_data" XML PATH '.') "o",
        XMLTABLE('link_data' PASSING "o"."link_data"
        COLUMNS
        "link" STRING  PATH 'link',
        "message" STRING  PATH 'message',
        "attachment_style" STRING  PATH 'attachment_style',
        "call_to_action" STRING PATH 'call_to_action',
        "child_attachments" XML PATH '.') "l",
        XMLTABLE('child_attachments'  PASSING "l"."child_attachments"
        COLUMNS
        "link" STRING PATH 'link',
        "image_hash" STRING  PATH 'image_hash',
        "name" STRING  PATH 'name',
        "description" STRING  PATH 'description',
        "type" STRING  PATH 'call_to_action/type'
    ) "c"
    ;;
  • 0
    Comment actions Permalink
    Avatar
    Matthias Korn

    Hi Jonas,

    thank you so much for sharing this!

    Best,
    Matthias

Please sign in to leave a comment.

Powered by Zendesk