?cursor? XML

How can I get the value of <?cursor?> in an xmlnode. It is something like this:

<AJCCcriteria class="- topic/stentry disease/AJCCcriteria ">
                        <?cursor?>Tumor with invasion into any of the following: aorta (ascending, arch, or
                descending), arch vessels, intrapericardial pulmonary artery, myocardium, trachea,
                esophagus
               
                    </AJCCcriteria>

a <?something?> is a XMLProcessingInstruction node
so you can advance thru the sub nodes and test if the current node isA XMLProcessingInstruction

Otherwise you can use xql with something like, relative to your node AJCCcriteria,
var xqlList as xmlNodeList=myNode.xql(“processing-instruction()”)
then your list will contain all the processing instructions (in your case just one)

If you want to select a specific instruction in your node you can use:
… myNode.Xql(“processing-instruction(‘cursor’)”)
now your list will contain only the cursor processing instructions

Whatever this istruction means

Thanks. That seems to be the case but it also seems like a XMLProcessingInstruction node does not have a “value” property that I can extract

Text usually resides in an XMLTextNode that is a Child of the current node. Ie., most of the time myNode.Value is not the text. It would be in mynode.FirstChild.Value.

Thanks. Already tried that. It seems like an ProcessingInstruction node does not have a “value” property. Neither the ToString method seems to work on it.

no
In your case value is empty since you have an instruction without any value, but only a name

if you change for test with something like <?xojo test?> then you will find that the XMLProcessingInstruction will have xojo as name, and test as value

Thanks. Very enlightening. The problem is that I am trying to extract the text after <?cursor?>. I thought that this text was the value of the processing instruction node. What I need in my example is : “Tumor with invasion into any of the following: aorta (ascending, arch, or descending), arch vessels, intrapericardial pulmonary artery, myocardium, trachea, esophagus”. I tried to get it as the value of ‘cursor’ node and as a text node (child of AJCCcriteria node) with no luck.

That is easy:
var xqlList as xmlNodeList=myNode.xql(“text()”)
if xqlList.length>0 then //there is a sub textNode
var xn as xmlNode=xqlList.item(0)
var myText as string=xn.value
end if

If you note, is the same as looking for the processing instruction. In this case you are looking for text() IE textNodes.

Thanks. That worked.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.