PL/SQL getting part of a node that isn't a leaf? - sql

I have an XML file that I am trying to parse and process in PL/SQL. Everything has been solvable up to this point. I have a node where I need to get some information that isn't in the leaf.
<Division_Description Descriptor="00 Office">
<ID>788758885</ID>
</Division_Description>
I need the value from "descriptor". I am using EXTRACTVALUE() to parse most of the nodes that I need. If I use
EXTRACT(Value(p),'/Division_Description').getStringVal() as v_DIVISON_DESCRIPTION,
I get the above little XML.
I tried using #descriptor at the end of the extract and extractvalue functions (as in extract(..., '.../Division_Description#Descriptor') but that resulted in an exception.
How do I get the Descriptor?

You were close. Try this:
/Division_Description/#Descriptor

Related

workfusion webelement has two variable ad doesnt take anything

Workfusion I am trying to make two variables through web-element. When running individually its great but when running separately it has problems.
Please see the picture for the same. This doesn't get executed.
If your XPath has any variable then try the giving a value like following:
//*[#id="mv-tiles"]/a[${i}]
and you can keep changing value of i through loop. A variable inside another will throw error in Workfusion RPA Express.
The ${} evaluates the whole it's body.
Does the following, without nested ${} execute OK?
${webrange[countertemp]}

Dynamic, Nested Replace

I'm using SQL Server 2008 and need to strip out quite a bit of data within a string. Because of the nature and variability of the string, I think I'm needing to use multiple, nested REPLACE commands. The problem is each REPLACE needs to build on the previous one. Here is a sample of what I'm looking at:
<Paragraph><Replacement Id="40B"><Le><Run Foreground="#FFFF0000">Treatment by </Run></Le><Op isFreeText="True"><Run Foreground="#FFFF0000">test</Run></Op><Tr><Run Foreground="#FFFF0000">. </Run></Tr></Replacement></Paragraph>
Essentially, I need it to return just the text outside of the <> brackets so for this example it would be:
Treatment by test.
Also, I wanted to mention that the strings inside the <> brackets can vary quite a bit for each row both by content and length, but it isn't relevant for what I'm needing other than making it more complex for replacing.
Here is what I've tried:
REPLACE(note,substring(note,patindex('<%>',note),CHARINDEX('>',note) - CHARINDEX('<',note) + 1),'')
And it returns:
<Replacement Id="40B"><Le><Run Foreground="#FFFF0000">Treatment by </Run></Le><Op isFreeText="True"><Run Foreground="#FFFF0000">test</Run></Op><Tr><Run Foreground="#FFFF0000">. </Run></Tr></Replacement></Paragraph>
Somehow I need to keep going with replacing each of the <> brackets but don't know how to proceed. Any help or guidance would be greatly appreciated!!!
Depending on how you have that string holding the HTML fragment available you could try to use something like:
SELECT convert(xml, '<Paragraph><Replacement Id="40B"><Le><Run Foreground="#FFFF0000">Treatment by </Run></Le><Op isFreeText="True"><Run Foreground="#FFFF0000">test</Run></Op><Tr><Run Foreground="#FFFF0000">. </Run></Tr></Replacement></Paragraph>').value('/', 'varchar(255)') as stripped
You convert it to XML and then use the built in xml parser function "value".

Parsing a SQL spatial column in Python

I am struggling a bit as I am new to programming. I am currently writing a python script and I am a bit stuck. The goal is to parse some spatial information the gets pulled from SQL to a format that is usable for my py script down the line.
I was able to CAST through a SQL query and fetchall using the obdc module. However once I fetch the data that is where it gets trick for me. Here is an example of a print from the fetchall:
[(u'POLYGON ((7014.186279296875 6602.99658203125 1612.5, 7015.984375 6600.416015625 1612.5))',), (u'POLYGON ((6730.962646484375 6715.2490234375 1522.5, 6730.0869140625 6714.13916015625 1522.5))',)]
I am not exactly sure what I am getting here it is like a list of tuples. which I have tried converting to a list of list, but there must be something I am missing.
Here is the usable format I am looking for:
[[7014.186279296875, 6602.99658203125, 1612.5], [7015.984375, 6600.416015625, 1612.5]]
[[6730.962646484375, 6715.2490234375, 1522.5], [6730.0869140625, 6714.13916015625, 1522.5]]
Any ideas of how I can accomplish this? Maybe there is a better way to CAST in SQL or a module in python that would be easier to use instead of just doing a cursor.fetchall() and parsing? Or any any parsing help would be useful. Thanks.
If you want to do parsing, that should be straight forward. For example you've provided next code would do the thing:
result = []
for element in data:
single_elements = element[0][10:-2].split(', ')
for se in single_elements:
row = str(se).split(' ')
result.append([float(a) for a in row])
Result will contain what you need. If parsing is not an option, then paste some of your code so I can see how you're fetching data.

Not Able to Parse multiple records in Libxml2

I have a collection of records which i am parsing using libxml2.
example:
<Customer><name>ABC</name><age>22</age></Customer>
<Customer><name>XBF</name><age>23</age></Customer>
<Customer><name>AHG</name><age>22</age></Customer>
<Customer><name>KKK</name><age>24</age></Customer>
<Customer><name>NNN</name><age>25</age></Customer>'
The problem is that on parsing i am able to parse the first record but the consecutive records are not parsed as the sax delegate startElementSAX() is not being called after parsing the first record.
Is there any way to call this SAX delegate function after the first record is parsed.
Thanks in Advance!
Because they all got the same name. How to distinguish an element from another? You need to make it be an array:
<Customers>
<Customer><name>ABC</name><age>22</age></Customer>
<Customer><name>XBF</name><age>23</age></Customer>
<Customer><name>AHG</name><age>22</age></Customer>
<Customer><name>KKK</name><age>24</age></Customer>
<Customer><name>NNN</name><age>25</age></Customer>
</Customers>
There is also an extra character at the end of the xml which I assume is a copy-paste mistake.

What's the correct format to extract an attribute from an element of some id using selenium.getAttribute()?

I've tried tracking down the appropriate syntax to extract an attribute using selenium.getAttribute(someXPath), and while I've come across many examples, nothing seems to work. From what I can tell, standard xpath syntax, such as:
//*[#id='someID']
doesn't work. What's the correct format to extract an attribute from an element of some id?
So it seems as if that format is almost correct. The correct string would be
//*[#id="someId"]#someAttribute
Another solution is to use
"someId#someAttribute"
which actually is "better" as the former can generate errors for IE.
Also, it seems that when an element contains no attributes at all, the error message is "attributeValue is null" instead of the normal "Element / attribute not found".