Here is a XML file:
<ROOT>
<A>
<B>2</B>
<C>3</C>
<D>4</D>
</A>
</ROOT>
How to get the tag name "C" through xPath. The function name() does not work here in extract.
It reports Errors:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00601: Invalid token
gXmlDOM is the xml string above, how to do this in SQL?
select XMLType(gXmlDOM).extract(p_xmlPath).getStringVal() from dual;
This might be what you're looking for...
Select xmltype('<ROOT><A><B>2</B><C>3</C><D>4</D></A></ROOT>')
.extract('ROOT/A/*[2]')
.getrootelement()
From dual;
Related
I have the following XML:
<Main>
<ResultOutput>
<Name>TEST1</Name>
<Value>D028</Value>
</ResultOutput>
<ResultOutput>
<Name>TEST2</Name>
<Value>Accept</Value>
</ResultOutput>
<ResultOutput>
<Name>TEST3</Name>
<Value />
</ResultOutput>
</Main>
What I want is to get the value of the <value> tag in SQL.
Basically want to say get <value> where <Name> has the value of TEST1, as an example
This is what I have at the moment, but this depends on the position of the XML tag:
XMLResponse.value(Main/ResultOutput/Value)[5]', nvarchar(max)')
The best way to do this is not to put extra where .value clauses, but to do it directly in XQuery.
Use [nodename] to filter by a child node, you can even nest such predicates. text() gets you the inner text of the node:
XMLResponse.value('(/Main/ResultOutput[Name[text()="TEST1"]]/Value/text())[1]', 'nvarchar(max)')
Below is an example using the sample XML in your question. You'll need to extend this to add namespace declarations and the proper xpath expressions that may be present in your actual XML as your query attempt suggests.
SELECT ResultOutput.value('Value[1]', 'nvarchar(100)')
FROM #xml.nodes('Main/ResultOutput') AS Main(ResultOutput)
WHERE ResultOutput.value('Name[1]', 'nvarchar(100)') = N'TEST1';
My response data is having text in it.
I am not able to get data from any of the fields using xpath from this response.
Karate shows "xml parsing failed, response data type set to string: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 716; The entity "nbsp" was referenced, but not declared." all xpaths
(Eg: response/transaction/values/data/#name)
I need to verify the commentDisplay tag in below xml. How to proceed?/ Is there any way to remove before fetching the value using xpath?
<Response>
<RequestID>1234</RequestID>
<transaction>
<values>
<data name="firstName">Sumith</data>
<data name="lastName">Menon</data>
</values>
<commentDisplay>
<top>Please Verify IDCard</top>
<bottom/></commentDisplay>
</transaction>
</Response>
is invalid in XML, refer: https://stackoverflow.com/a/36097922/143475
But you can correct this in one step:
* xml response = response.replaceAll(' ', ' ')
I have a requirement where i need to query database using saxon sql;query by applying where clause, where database_table.ProductID should match with incoming xml input productId
Here is what i tried so far:
<sql:query connection="$sql.conn" table="table_name" column="Product_ID" row-tag="row" column-tag="col" where="Product_ID="<xsl:value-of select="ProductItem/ProductItemId/text()"/>"" />
I am getting following Exception:
SXXP0003: Error reported by XML parser: Element type "sql:query" must be followed by either attribute specifications, ">" or "/>".
I am finding it difficult to format the where clause in XPath, can any one suggest what would be correct format. Thanks in Advance.
Try to use to use an attribute value template where you put the XPath expression in curly braces {...}, as in
<sql:query connection="$sql.conn" table="table_name" column="Product_ID" row-tag="row" column-tag="col" where="Product_ID="{ProductItem/ProductItemId}""/>
My XML :
<root>
<row>
<name>ABC</name>
<contacts> C1 <abc#abc.com> C2 <xyz#xyz.com> </contacts>
</row>
<root>
When i start parsing
It will be break after C1 string. Coz it got < element. and give me error like here,
parser error : Error Domain=NSXMLParserErrorDomain Code=68 "The
operation couldn’t be completed. (NSXMLParserErrorDomain error 68.)"
UserInfo=0x143e3ba0 {NSXMLParserErrorLineNumber=1,
NSXMLParserErrorColumn=966, NSXMLParserErrorMessage=error parsing
attribute name }
The question seems be easy, But its not.
Please response with your best solution.
I'm trying to extract a chunk of XML (ie the whole xml of a node, not just content) using an xpath query in SQL. I can extract a single content field but am not sure how to do the above.
Say the xml is as follows
<head>
<instance>
<tag1>
<tag2>data</tag2>
<tag3>data</tag3>
</tag1>
</instance>
</head>
I would like to extract all of the xml inside tag1, and was hoping something like this would work in a SQL query:
Table.value('(/head/instance/tag1)[1]', 'varchar(max)') as "col"
Any help would be great.
Thanks
this should work:
Select Cast(Table.xmlcolumnname.query('/head/instance/tag1') as varchar(max)) 'col';
(its not checked! may contain typo..)