XML Content Model
The XML Content Model provides access to XML-based content.
The XML Content Model supports the ability to access components based on XPath expressions. XPath expressions are strings that define which elements or attributes are required by the caller. The XML Content Model hides the details of constructing various objects and compiling expressions that are typically required by XPath support. This makes it simpler to call from Python scripting.
The XML Content Model includes a function that returns the XML document as a string. This allows Python script users to use their preferred Python library to parse the XML.
API
Return | Method | Description |
---|---|---|
String |
getXMLAsString() |
Returns the XML as a string. |
number |
getNumericValue(String xpath) |
Returns the result of evaluating the path with return type of numeric (for example, count the number of elements that match the path expression). |
boolean |
getBooleanValue(String xpath) |
Returns the boolean result of evaluating the specified path expression. |
String |
getStringValue(String xpath, String attribute) |
Returns either the attribute value or XML node value that matches the specified path. |
List of strings |
getStringValues(String xpath, String attribute) |
Returns a list of all attribute values or XML node values that match the specified path. |
List of lists of strings |
getValuesList(String xpath, <List of strings> attributes, boolean
includeValue) |
Returns a list of all attribute values that match the specified path along with the XML node value if required. |
Hash table (key:string, value:list of string) |
getValuesMap(String xpath, String keyAttribute, <List of strings> attributes,
boolean includeValue) |
Returns a hash table that uses either the key attribute or XML node value as key, and the list of specified attribute values as table values. |
boolean |
isNamespaceAware() |
Returns whether the XML parsers should be aware of namespaces. Default is
False . |
void |
setNamespaceAware(boolean value) |
Sets whether the XML parsers should be aware of namespaces. This also calls
reset() to ensure changes are picked up by subsequent calls. |
void |
reset() |
Flushes any internal storage associated with this content model (for example, a cached DOM object). |
Nodes and outputs
This table lists nodes that build outputs which include this type of content model.
Node name | Output name | Container ID |
---|---|---|
Most model builders |
Most generated models |
"PMML" |
"autodataprep" |
n/a |
"PMML" |
Example script
The Python scripting code to access the content might look like this:
results = []
modelbuilder.run(results)
modeloutput = results[0]
cm = modeloutput.getContentModel("PMML")
dataFieldNames = cm.getStringValues("/PMML/DataDictionary/DataField", "name")
predictedNames = cm.getStringValues("//MiningSchema/MiningField[@usageType='predicted']", "name")