Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
extract XML
#1
i keep getting a interface pointer variable is 0 error.  not sure where i am wrong.  documentation is a little confusing when it comes to this functionality. my requested output should be

measure
dimension
dimension
measure
measure

thanks for any assistance. i pasted the XML in the code to test, plan is to read XML file from QM and get the node values... would the variables and function call change?

Macro Macro1
Trigger AF1     Help - how to add the trigger to the macro
Code:
Copy      Help
out
ARRAY(IXmlNode) a
str s=
;<?xml version="1.0" encoding="utf-8"?>
;<!-- build 20183.18.1018.1932                               -->
;<workbook original-version="18.1" source-build="2018.3.0 (20183.18.1018.1932)" source-platform="win" version="18.1" xmlns:user="http://www.tableausoftware.com/xml/user">
;;<document-format-change-manifest>
;;;;<WindowsPersistSimpleIdentifiers />
;;</document-format-change-manifest>
;;<preferences>
;;;;<preference name="ui.encoding.shelf.height" value="24" />
;;;;<preference name="ui.shelf.height" value="26" />
;;</preferences>
;;<datasources>
;;;;<datasource caption="test" inline="true" name="federated.059vgdd0g7q5861coqvs91sv06g4" version="18.1">
;;;;;;<aliases enabled="yes" />
;;;;;;<column datatype="integer" name="[Number of Records]" role="measure" type="quantitative" user:auto-column="numrec">
;;;;;;;;<calculation class="tableau" formula="1" />
;;;;;;</column>
;;;;;;<column caption="Age" datatype="integer" name="[age]" role="measure" type="quantitative" />
;;;;;;<column caption="Gender" datatype="string" name="[gender]" role="dimension" type="nominal" />
;;;;;;<column caption="Name" datatype="string" name="[name]" role="dimension" type="nominal" />
;;;;;;<column caption="Rank" datatype="integer" name="[rank]" role="measure" type="quantitative" />
;;;;;;<layout dim-ordering="alphabetic" dim-percentage="0.473008" measure-ordering="alphabetic" measure-percentage="0.498715" parameter-percentage="0.0282776" show-structure="true" />
;;;;;;<semantic-values>
;;;;;;;;<semantic-value key="[Country].[Name]" value="&quot;United States&quot;" />
;;;;;;</semantic-values>
;;;;</datasource>
;;</datasources>
;</workbook>

IXml x._create
IXmlNode e
x.ToString(s)

e= x.Path("/workbook/datasources/datasource/column/@role")
str v2 = e.Value
out v2
#2
the error is because you used x.ToString should be

x.FromString
 
Code:
Copy      Help
IXml x._create
IXmlNode e
x.FromString(s)
e= x.Path("workbook/datasources/datasource/column/@role")
str v2 = e.Value
out v2

full code to extract all the role values in column
Code:
Copy      Help
out
str s=
;<?xml version="1.0" encoding="utf-8"?>
;<!-- build 20183.18.1018.1932                               -->
;<workbook original-version="18.1" source-build="2018.3.0 (20183.18.1018.1932)" source-platform="win" version="18.1" xmlns:user="http://www.tableausoftware.com/xml/user">
;;<document-format-change-manifest>
;;;;<WindowsPersistSimpleIdentifiers />
;;</document-format-change-manifest>
;;<preferences>
;;;;<preference name="ui.encoding.shelf.height" value="24" />
;;;;<preference name="ui.shelf.height" value="26" />
;;</preferences>
;;<datasources>
;;;;<datasource caption="test" inline="true" name="federated.059vgdd0g7q5861coqvs91sv06g4" version="18.1">
;;;;;;<aliases enabled="yes" />
;;;;;;<column datatype="integer" name="[Number of Records]" role="measure" type="quantitative" user:auto-column="numrec">
;;;;;;;;<calculation class="tableau" formula="1" />
;;;;;;</column>
;;;;;;<column caption="Age" datatype="integer" name="[age]" role="measure" type="quantitative" />
;;;;;;<column caption="Gender" datatype="string" name="[gender]" role="dimension" type="nominal" />
;;;;;;<column caption="Name" datatype="string" name="[name]" role="dimension" type="nominal" />
;;;;;;<column caption="Rank" datatype="integer" name="[rank]" role="measure" type="quantitative" />
;;;;;;<layout dim-ordering="alphabetic" dim-percentage="0.473008" measure-ordering="alphabetic" measure-percentage="0.498715" parameter-percentage="0.0282776" show-structure="true" />
;;;;;;<semantic-values>
;;;;;;;;<semantic-value key="[Country].[Name]" value="&quot;United States&quot;" />
;;;;;;</semantic-values>
;;;;</datasource>
;;</datasources>
;</workbook>

IXml x._create
x.FromString(s)
ARRAY(IXmlNode) a
x.Path("workbook/datasources/datasource/column" a)
int i
for i 0 a.len
,IXmlNode attr=a[i].Attribute("role")
,str s2=attr.Value
,out s2
#3
thanks for pointing that out... i changed it and it works, but only returns 1 value, the first value.... if you notice there are 6 similiar nodes that i wanted to return values for. so output should be

measure
dimension
dimension
measure
measure

whats the proper syntax for all values of similiar nodes?
#4
actually there are 5 in the posted code and output would be

measure
measure
dimension
dimension
measure


look at my previous post (full code to extract all the role values in column) to see how to extract all the values of role in column
#5
oh. i now see the full code. thanks for your help.

did you happen to create a "cheat sheet" to understand all the symbols/logic when working with variables, functions, pointers, COM etc and putting together statements?  just starting out and a little daunting trying to put things together... thanks for help


Forum Jump:


Users browsing this thread: 2 Guest(s)