libxml2 - get node(xmlNodePtr) content? - iphone

I parsed and have pointer xmlNodePtr upto category tag, But I want to get the value of the node(name) like TrailersFreeMovies , Trailers in an array.
<categories><category><name>TrailersFreeMovies</name><url>https://www.ex1.com/srs/index.php?cid=47</url></category><category><name>Trailers</name><url>https://www.ex1.com/srs/index.php?cid=45</url></category></categories>
guide me to parse this

XPath part of the api returns an array of nodes. See XPath examples.
Once you obtain the result of xmlXPathEvalExpression as xpathObj then the array is in xpathObj->nodesetval->nodeTab. nodesetval is a pointer to xmlNodeSet type.
xmlGetNodePath returns following values for the nodes of your sample xml matching the //name xpath expression:
/categories/category[1]/name
/categories/category[2]/name
So a specific answer to your question would be: apply xpath expression ("%s/name", xmlGetNodePath(categoryNode)) and process returned array of nodes. For each entry get the text with xmlNodeListGetString(doc, node->xmlChildrenNode, 1).

Related

how to use json_extract_path_text?

I am facing an issue with JSON extract using JSON_EXTRACT_PATH_TEXT in redshift
I have two separate JSON columns
One containing the modems the customer is using and the other one containing the recharge details
{"Mnfcr": "Technicolor","Model_Name":"Technicolor ABC1243","Smart_Modem":"Y"}
For the above, I have no issue extracting the Model_name using JSON_EXTRACT_PATH_TEXT(COLUMN_NAME, 'Model_Name') as model_name
[{"Date":"2021-12-24 21:42:01","Amt":50.00}]
This one is causing me trouble. I used the same method above and it did not work. it gave me the below error
ERROR: JSON parsing error Detail: ----------------------------------------------- error: JSON parsing error code: 8001 context: invalid json object [{"Date":"2021-07-03 17:12:16","Amt":50.00
Can I please get assistance on how to extract this using the json_extract_path_text?
One other method I have found and it worked was to use regexp_substring.
This second string is a json array (square braces), not an object (curly brackets). The array contains a single element which is an object. So you need to extract the object from the array before using JSON_EXTRACT_PATH_TEXT().
The junction for this is JSON_EXTRACT_ARRAY_ELEMENT_TEXT().
Putting this all together we get:
JSON_EXTRACT_PATH_TEXT(
JSON_EXTRACT_ARRAY_ELEMENT_TEXT( <column>, 0)
, 'Amt')
you can use json_extract_path_text like below example
json_extract_path_text(json_columnName, json_keyName) = compareValue
for more you can refer this article
https://docs.aws.amazon.com/redshift/latest/dg/JSON_EXTRACT_PATH_TEXT.html

Mirth channel XML : how to read value from inside of an element

How to read a list of values from Mirth Channel XML's <mapping> element? I can use msg to read one value. But what if there are list of values? Example:
<patient>
<name>names</name>
<patient>
If there is one value fornames defined, then simply performing <mapping>msg['patient']['name']</mapping> will return the value. But how to get only values if the names return more than one name? How to iterate and display in the same XML? I am doing Mirth for the first time and any help is appreciated.
I understand your question in this way.. so you mean if you receive the XML in this fashion
<patient>
<name>names</name>
<name>name1</name>
</patient>
then how to iterate and fetch only 'name' tags value. If my understanding is correct then place the below code in your source transformer.
var nameLen = msg['name'].length();
for(i=0;i<nameLen;i++){
// Your Mapping Logic
logger.debug(msg['name'][i].toString());
}

Separate values from array

This string response i am getting from server.
2001,wooza,0420224346,J Wratt ,+61417697070,2013-55-1803-55-54.jpg,No<br />2002,wooza,0420224346,J Wratt ,+61417697070,2013-56-1803-56-17.jpg,No<br />2003,testing,9894698946,ggh hjj,9894598945,2013-11-1811-11-40.jpg,Yes<br />
I separate each record through "br" and stored it in a array.How do i access (2013-55-1803-55-54.jpg) value from array.
You can get through objectAtIndex method.
Alrenatively its better you keep the all the related data of your custom class and storing that in array.
Most of the times you will need more than one value during display. In that case, just get the object from array and show related info through object reference.
Take comma separated strings from an intended element in a different array and use NSPredicate to get the string containing .jpg in it.

PostgreSQL CASE: position within text array

I am currently successfully using a CASE expression to update an empty column based on attributes from other columns. For example
UPDATE table SET cat = CASE
WHEN term = '{"Boulder"}' then 'Boulder'
However, I need to do the same but on an text array and particularly when an element is in a specific position within that array.
For example if the data looks like
{"Boulder, Tree, Bush"}
WHEN position('Tree' in term) > 0 then 'Boulder'
But I receive an error message
function pg_catalog.position(character varying[], unknown) does not exist
I have used position in a function before so I am not sure why PostgreSQL does not like it in this situation.
Is there a way to using a CASE expression whilst determining the position of a text element within an array.
Apparently your term column is defined as an array, e.g. varchar[]. The position function only works with scalar values, not with arrays.
If you want to test if an element is contained in an array you need to use a different operator: #>
update foobar
set cat = 'Boulder'
where term #> '{"Boulder"}'
The expression '{"Boulder"}' creates an array with a single element. It's equivalent to array['Boulder'] (which I find more readable). So the above where condition updates all rows where the array term contains all elements of the array on the right hand side of the operator. In this case it's only a single element you are testing for.
More details about the array functions and operators can be found in the manual: http://www.postgresql.org/docs/current/static/functions-array.html
Edit after the requirements have changed
To find and update only those where boulder is in the first, second or third place, you can use this:
update foobar
set cat = 'Boulder'
where 'Boulder' in (term[1], term[2], term[3]);

iphone sdk - how do i do this if else checking logic. checking an NSMutableArray for a possible value against parsed xml

EDIT*
hi guys , lets say i have an array with 5 Strings = "1","2","3","4","5".
Im also doing parsing of xml. So how do i check whether a parse xml value is the same value of either one of the objects IN the array?
solved * i put them in a for loop to, looping through each array.value and making a root (if else) that checks whether the value in the array is equal to the parsed xml value