Parse XML file, read a tag with whitespaces value.
Hi all,
I've got a problem with reading a spaced value record from xml file using sys.xmltype.
My xml file contains the following:
<?xml version = '1.0'?>;
<ROWSET>
<ROW num="1">
<FIRSTNAME>Nik</FIRSTNAME>
<LASTNAME> </LASTNAME>
<AGE>30</AGE>
</ROW>
</ROWSET>
As you see last name contains four spaces!
Now when I'm trying to read value from LASTNAME record I'm getting a NULL value, but I want it to return me those 4 spaces as they are.
Here is a short code description of what I'm doing:
declare
xml sys.xmltype;
str1 varchar2(100);
str2 varchar2(100);
begin
xml := sys.xmltype.createxml(fileContentClob); -- I copy the file content into the fileContentClob variable.
If xml.existsnode('//ROW['1']/LASTNAME') > 0 Then -- This condition evaluates as true
str1 := xml.extract('//ROW['1']/LASTNAME/text()'); -- str1 gets NULL value :(, I want spaces as they are in the file.
str2 := xml.extract('//ROW[' || 1 || ']/LASTNAME').getstringval; -- str2 gets <LASTNAME/> null tag :(.
End If;
end;
Seems like when it createxml from the fileContentClob it ignores the spaces and find LASTNAME as a null field.
Do you have any suggestions on how can I fix that, so I can read whitespaces as they are in the file?
I generate the file also using a xml toolpackage from oracle:
declare
strSqlStmt Varchar2(300);
varCtxHdl dbms_xmlquery.ctxhandle;
varClob Clob;
begin
strSqlStmt := 'SELECT FIRSTNAME,LASTNAME,AGE FROM USERS WHERE ROWNUM =1';
varCtxHdl := dbms_xmlquery.newcontext(strSqlStmt);
varClob := dbms_xmlquery.getxml(varCtxHdl);
dbms_xmlquery.closecontext(varCtxHdl);
End;
Even if the STORE AS CLOB clause is used to store the data and preserve whitespace for the XML, the actual extraction of data seems to be removing whitespace...
SQL> ed
Wrote file afiedt.buf
1* create table t (xml xmltype) xmltype xml store as clob
SQL> /
Table created.
SQL> ed
Wrote file afiedt.buf
1 insert into t (xml)
2 values (q'[<?xml version = '1.0'?>
3 <ROWSET>
4 <ROW num="1">
5 <FIRSTNAME>Nik</FIRSTNAME>
6 <LASTNAME> </LASTNAME>
7 <AGE>30</AGE>
8 </ROW>
9* </ROWSET>]')
SQL> /
1 row created.
SQL> select * from t;
XML
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<FIRSTNAME>Nik</FIRSTNAME>
<LASTNAME> </LASTNAME>
<AGE>30</AGE>
</ROW>
</ROWSET>
SQL> set null NULL
SQL> select x.rnum, x.firstname, x.lastname, x.age
2 from t
3 ,xmltable('/ROWSET/ROW'
4 PASSING t.xml
5 COLUMNS rnum NUMBER PATH '/ROW/@num'
6 ,firstname VARCHAR2(10) PATH '/ROW/FIRSTNAME'
7 ,lastname VARCHAR2(10) PATH '/ROW/LASTNAME'
8 ,age NUMBER PATH '/ROW/AGE'
9 ) x
10 /
RNUM FIRSTNAME LASTNAME AGE
1 Nik NULL 30
SQL>
Similar Messages
-
Script for generating XML file ... problem with null values
Greetings everyone,
i come here with a question that troubles me for some time now. I have a script which i run from SQLPLUS every now and then to generate an XML file.
Problem is that data which needs to be in XML is not allways <> NULL and i need to hide those tags that are empty </tag>.
I will post below my script and if you could help me with it it would be really great!
Thanks for reading!
set long 20000000
set long 20000000
set linesize 32000
SET ECHO OFF
SET TRIMSPOOL on
SET HEADING OFF
SET PAGESIZE 50000
SET VERIFY OFF
SET FEEDBACK OFF
SET TERMOUT OFF
spool C:\test.xml
set serveroutput on
begin
dbms_output.put_line('<?xml version="1.0" encoding="utf-8" ?>');
end;
SELECT
XMLELEMENT("ReportRoot",XMLATTRIBUTES('http://www.w3.org/2001/XMLSchema-instance' as "xmlns:xsi", 'http://www.w3.org/2001/XMLSchema' as "xmlns:xsd" , '1.0' as "Version",sysdate as "CreationDate",to_char(sysdate,'hh:mm:ss') as "CreationTime",'1524544845' as "id"),
XMLELEMENT("Porocila",XMLELEMENT("JOLY",(SELECT XMLAGG (XMLELEMENT("RefNrReport",replace('SON'||to_char(ref_ST,'00000'),' ',''))) from access_table_2 where ref_ST = &1),
XMLELEMENT("ReportDate",sysdate),XMLELEMENT("Labeling",'545254450'),
(SELECT XMLAGG (XMLELEMENT("Reportf",
XMLELEMENT("access",access),
XMLELEMENT("date",date),
XMLELEMENT("datep",datep),
XMLELEMENT("ModificationInfo",'M'),XMLELEMENT("ModificationReason",modireason)))
from v_xml_test where id_dok = &1 and ind_print = '1'))))
.extract('/*')
from dual
spool off
exitNow lets pretend that XMLELEMENT("datep",datep), is sometimes NULL and i do not want to display it.may be
with t as
select sysdate datep from dual union all
select null datep from dual
select xmlagg(xmlelement("Reportf",
case when datep is not null then XMLELEMENT("datep", datep)
end
from t -
Parse xml file and extract tags (not well formed)
im writing an xml editor and i would like to extract tags from a string of xml. And the string doesnt have to be well formed xml.
An example "</a><b asd="kjkj"></b>"
Output
end tag (a)
start tag (b)
end tag (b)
Sax nor stax does the job since they want well formed document. and i dont want to write a parser myself.
any suggestionsim writing an xml editor and i would like to extract
tags from a string of xml. And the string doesnt have
to be well formed xml.Then you aren't writing an XML editor. And as you observe, existing parsers don't work for you because they are don't have the requirement to process garbage. Where did you get that requirement from, anyway? -
How to compare after parsing xml file
Hi,
following code, parse the input.xml file, counts how many nodes are there and writes the node name and its value on screen.
1) i am having trouble writing only node name into another file instead of writing to screen.
2) after parsing, i like to compare each node name with another .xsd file for existence.
Please keep in mind that, input.xml is based on some other .xsd and after parsing i have comparing its tag with another .xsd
Need you help guys.
thanks
* CompareTags.java
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
/** This class represents short example how to parse XML file,
* get XML nodes values and its values.<br><br>
* It implements method to save XML document to XML file too
public class CompareTags {
private final static String xmlFileName = "C:/input.xml";
int totalelements = 0;
/** Creates a new instance of ParseXMLFile */
public CompareTags() {
// parse XML file -> XML document will be build
Document doc = parseFile(xmlFileName);
// get root node of xml tree structure
Node root = doc.getDocumentElement();
// write node and its child nodes into System.out
System.out.println("Statemend of XML document...");
writeDocumentToOutput(root,0);
System.out.println("totalelements in xyz tag " + totalelements);
System.out.println("... end of statement");
/** Returns element value
* @param elem element (it is XML tag)
* @return Element value otherwise empty String
public final static String getElementValue( Node elem ) {
Node kid;
if( elem != null){
if (elem.hasChildNodes()){
for( kid = elem.getFirstChild(); kid != null; kid = kid.getNextSibling() ){
if( kid.getNodeType() == Node.TEXT_NODE ){
return kid.getNodeValue();
return "";
private String getIndentSpaces(int indent) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < indent; i++) {
buffer.append(" ");
return buffer.toString();
/** Writes node and all child nodes into System.out
* @param node XML node from from XML tree wrom which will output statement start
* @param indent number of spaces used to indent output
public void writeDocumentToOutput(Node node,int indent) {
// get element name
String nodeName = node.getNodeName();
// get element value
String nodeValue = getElementValue(node);
// get attributes of element
NamedNodeMap attributes = node.getAttributes();
System.out.println(getIndentSpaces(indent) + "NodeName: " + nodeName + ", NodeValue: " + nodeValue);
for (int i = 0; i < attributes.getLength(); i++) {
Node attribute = attributes.item(i);
System.out.println(getIndentSpaces(indent + 2) + "AttributeName: " + attribute.getNodeName() + ", attributeValue: " + attribute.getNodeValue());
// write all child nodes recursively
NodeList children = node.getChildNodes();
//int totalelements = 0;
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
// System.out.println("child value.."+child);
if (child.getNodeType() == Node.ELEMENT_NODE) {
writeDocumentToOutput(child,indent + 2);
if(node.getNodeName() == "DATA"){
totalelements = totalelements+1;}
//System.out.println("totalelements in DATA tag " + totalelements);
/** Parses XML file and returns XML document.
* @param fileName XML file to parse
* @return XML document or <B>null</B> if error occured
public Document parseFile(String fileName) {
System.out.println("Parsing XML file... " + fileName);
DocumentBuilder docBuilder;
Document doc = null;
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setIgnoringElementContentWhitespace(true);
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
catch (ParserConfigurationException e) {
System.out.println("Wrong parser configuration: " + e.getMessage());
return null;
File sourceFile = new File(fileName);
try {
doc = docBuilder.parse(sourceFile);
catch (SAXException e) {
System.out.println("Wrong XML file structure: " + e.getMessage());
return null;
catch (IOException e) {
System.out.println("Could not read source file: " + e.getMessage());
System.out.println("XML file parsed");
return doc;
/** Starts XML parsing example
* @param args the command line arguments
public static void main(String[] args) {
new CompareTags();
}hi,
check out the following links
Check this blog to extract from XML:
/people/kamaljeet.kharbanda/blog/2005/09/16/xi-bi-integration
http://help.sap.com/saphelp_nw04/helpdata/en/fe/65d03b3f34d172e10000000a11402f/frameset.htm
Check thi link for Extract from any DB:
http://help.sap.com/saphelp_nw04s/helpdata/en/58/54f9c1562d104c9465dabd816f3f24/content.htm
regards
harikrishna N -
Hi
Anyone know about support for parsing XML files in LabVIEW?
(I mean specific XML support, I'm familiar with LabVIEWs file functions)
regards
Jan
Sent via Deja.com http://www.deja.com/
Before you buy.I assume you are referring to:
http://www.savarese.org/oro/software/OROMatcher1.1.html
Have you considered asking Savarese?
Peace,
Cameron Purdy
Tangosol, Inc.
http://www.tangosol.com
+1.617.623.5782
WebLogic Consulting Available
"Laurent Mentek" <[email protected]> wrote in message
news:[email protected]..
Hi all,
I'm started to develop with BEA WebLogic and I use ORACLE 8.1.6
database.
We need to map some XML tags as metadata in the database.
Here is a concrete example with part of our XML files:
XML files :
<target>EDU</target>
<question>
<para>
Please could you provide some references on nutritional status in
the frail elderly?
</para>
</question>
I use OROMatcher to parse xml files and it work fine.
I can extract every element in line with success , but don't extract the
value in <para> tag, for example.
I don't no how to use the MULTILINE_MASK option and the ^ or $ to get
this line.
Anyone could give me an example of metadatas extaction using or no the
MULTILINE_MASK option?
Thanks a lot for your help.
Laurent. -
How to parse XML files from normal FTP Servers?
I want to parse xml files from a normal FTP Servers , NOT the sap application severs itself. How can i do that?
I know how to use the SAPFTP getting and putting files ,but I don't want to download and then parse it.
Who knows how to parse it directly? I Just need to read the contents into a database.
Thanks.I want to parse xml files from a normal FTP Servers , NOT the sap application severs itself. How can i do that?
I know how to use the SAPFTP getting and putting files ,but I don't want to download and then parse it.
Who knows how to parse it directly? I Just need to read the contents into a database.
Thanks. -
XML file to Proxy Scenario with BPM - ID Steps
Hi Guys,
Any one can help me to find about the scenario XML file to ABAP Proxy with BPM, ID steps please. Any link or logical routing, receiver determination and interface determination idea. Please correct me,
I have created Business Service as sender to send one xml file to BPM, BPM is sending a message to SNC system. I have created 2 receiver determinations, but I am confusing in interface determination, where to declare OM?
Please can any one respond bit quicker.
Thanks in advance
Regards
SanES Repository
*Service Interfaces*
Create one outbound service interface for XML file.
Create one Inbound synchronous Interface for SNC system.
Create one Abstract Asynchronous interface ,same message type as you used for outbound service interface .This is for Integration process receive step.
Create one Abstract async interface for receiving the response from SNC system in Integration process.
Create one Abstract synchronous interface to be used in the Integration process for Send sync step.
Create on inbound asyn service interface for sending the response from integration process (received from SNC system) to the Receiver System.
Operation Mapping.
Create an Operation Mapping using Abstract sync interface and inbound syn interfaces.
Integration Process
start--->receive Step---->send Synchronous step----->send step.
Create two container elements
first with abstrat async interface for the XML request.
second for abstract asyn interface with the XML response structure (asyn receiver system structure)
In the send sync step select your abstract syn interface from the F4 help.and select the corresponding request and response message from the container element you defined earlier.
Integration Directory.
Create one sender File adapter Communication channel for XML file reading.
Create two receiver communication channel for sync system(receiver XI adapte for ABAP PROXY) and other for asyn receiver system .
Create 3 receiver determination
1.from sender to Integration process.
2.from Integration process to SNC system.
3. from Integration process to Asyn Receiver System.
Create 3 Interface determination.
Specify Operation mapping while you are creating interface determination from Integration Process to Syn BS.
Create one sender agreement
Create two Receiver agreement.
Regards
Kubra Fatima. -
How to parse xml file in midlet
Hi Guys,
i wish to parse xml file and display it in my midlet. i found api's supporting xml parsing in j2se ie., in java.net or j2se 5.0. Can u please help me what package to use in midlet?
how to parse xml info and display in midlet? Plz reply soon......Thanks in advance....i have exactly the same problem with KXml2, but using a j2me-polish netbeans project.
i've tried to work around with similar ways like you, but none of them worked. now i've spent 3 days for solving this problem, i'm a bit disappointed :( what is wrong with setting the downloaded kxml2 jar path in libraries&resources?
screenshot -
When using saxParser.parse(XMLfile, handler) to parse XML file, How to stop the parsing but not exit. I catched thread interrupted in startElement(), but can not stop it because it still go through all other startElement()s and endElement()s. Is there any method or class can stop parse XML?
Appreciate your help!
EdwardPlease look at the technote:
http://access1.sun.com/technotes/01185.html
Hope this helps.
Michelle Cope
Sun Microsystems. -
Error in retrieving and parsing XML File
Hi Folks
I am Working on People centric user interface, While i am custimizing a application in Business application Builder i am getting this error
" Error in retrieving and parsing XML File "
can any body look on this and give me the solution
it will be rewarded
Regards
M.S.KumarHello,
As mentionned by SAP_TECH, avoid to use the BAB.
Go to CRMC_BLUEPRINT_C and use the different option in the menu to customize the field group, toolbar group, events, ...
Use the PCUI cookbook to find your way.
Regards,
Fred -
Hello All,
There is a requirement for parsing of XML files to ABAP.
1.How do we pick an XML file from Application server and also from FTP server?
2.After picking the XML file how to parse that XML file to process it to create material master?Hi,
Ur scenario is File to R/3
For creating material master ..i guess there is IDoc named MATMAS.
U can make use of it and execute File to IDoc Scenario.
link for File to IDoc--
https://www.sdn.sap.com/irj/scn/wiki?path=/display/xi/fileToIDOC&
U need to pick XML file from FTP server...No need to parse XML file...just create data type which represents ur xml file structure and map it to IDoc fields.
regards,
Manisha -
How to parse xml file to read the tags
Hi All,
I am having a requirement to read the tags from the xml file(xml parsing).
The main issue is *xml file is stored in the table with xml type column* (not placed directly in the server) and we have to read the tags from that xml file.
Please help me to achieve it.
Regards,
Akshata
Edited by: Akshata on Mar 21, 2013 3:44 AMHi,
Akshata wrote:
The main issue is xml file is stored in the table clob/blob type column (not placed directly in the server) and we have to read the tags from that xml file.How is that an issue? On the contrary, it's better when the data already resides in the database, though it should be in an XMLType column to leverage the full capacity of the Oracle parser.
What's the datatype of the column exactly? CLOB or BLOB?
Either way you'll have to convert in to XMLType datatype using the XMLType constructor.
Did you go through the countless examples on this forum? Examples with XMLTable should be helpful.
Post some sample data and database version if you need additional guidance.
Thanks. -
Parse an xml file using cm tag
I have question about Content Management and weblogic portal 9.2
In VCR directory, I will have xml file with bellow structure
Test Repository
--->Test
----Test.xml
Test.xml File will be like
<main_content>
<content>
<Subject>Subject</Subject>
<grade><p>This is grade Data</p></grade>
<mark><p>This is mark Data</p><mark>
<content>
<main_content>
I have used below code to retrieve the above
<cm:getNode path="/Test Repository/Test/Test.xml" id="headernode" />
<cm:getProperty id="node" name="_content" />
Above code will show all the content on Jsp. i,e Subject This is grade Data This is mark Data
But I only want to retrieve the data of <grade> tag then how can I do this? Please help
How <cm> tag will help me here ?
Please provide sample code if have. Your help is highly appreciated.
Edited by: user11311969 on Sep 10, 2009 2:52 AM
Edited by: user11311969 on Sep 10, 2009 2:53 AMHi
Thanks a lot for your swipt reply.
I try this also But error is same.
<x:parse var="output" xml="${xml_data}" />
javax.servlet.ServletException: Unrecognized object supplied as 'xml' attribute to <parse>
at weblogic.servlet.jsp.PageContextImpl.handlePageException(PageContextImpl.java:409)
at jsp_servlet._portlets._news.__news._jspService(__news.java:
<%=xml_data%> returning me a output just as name of file and not content --- > test.xml
After putting isMultiple="false" i am getting output as ----> test.xml
resultId defination
The name of the script variable to store the value of the property in. If this is not specified, the value of the property will be printed in the JSP instead. The value of the property is returned as a collection by default, unless the isMultiple attribute is set to false.
I think this approch is simple if we can solve this. Is there ant other way same as using tag in jsp itself to retrieve required XML tags. Please reply.. Also i am using Jsp/Html Portlet and not Page Flow Portlet
Edited by: user11311969 on Sep 11, 2009 1:42 AM
Edited by: user11311969 on Sep 11, 2009 1:44 AM
Edited by: user11311969 on Sep 11, 2009 1:44 AM
Edited by: user11311969 on Sep 11, 2009 1:44 AM -
Parsing XML file with different languages (Xerces)
How do we code or program to an XML file with different
languages , say english and spanish. WHen we parse such a document with the default locale , the presence of special characters throws errors .For eg when I use xerces and use
DOMParser parser = new DOMParser();
try
// Parse the XML Document
parser.parse(xmlFile);
catch (SAXException se)
se.printStackTrace();
org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xfc) was found in the element content of the document.
System Error: void org.apache.xerces.framework.XMLParser.parse(org.xml.sax.InputSource)
So what locale do we set before we parse ?How to handle this problemYou need an encoding attribute in the xml declaration. If you don't, the parser assumes UTF-8, which are ASCII characters up to 127 - useful (only) for English.
So, something like this would allow you to use characters above 127, ISO-8859-1 is the encoding used by standard PCs.
<?xml version="1.0" encoding="ISO-8859-1"?>
You can find a (offical) list of encodings at:
http://www.iana.org/assignments/character-sets
I'm not sure about mixing various encodings. I think you have to resort external parsed entities, which can have their own encoding, but I think you cannot mix encodings in one XML file.
Good luck. -
How to parse XML file with namesapce?
Hi,
I am trying to parse an xml file having namespace. But no data is returned.
Sample Code:
public class XMLFileLoader
var xml:XML = new XML();
var myXML:XML = new XML();
var XML_URL:String = "file:///C:/Documents and Settings/Administrator/Desktop/MyData.xml";
var myLoader:URLLoader = null;
public function XMLFileLoader()
var myXMLURL:URLRequest = new URLRequest(XML_URL);
myLoader= new URLLoader(myXMLURL);
myLoader.addEventListener(Event.COMPLETE,download);
public function download(event:Event):void
myXML = XML(myLoader.data);
var ns:Namespace=myXML.namespace("xsi");
for(var prop:String in myXML)
trace(prop);
//Alert.show(myXML..Parameters);
//trace("Data loadedww."+myXML.toString());
//Alert.show(myXML.DocumentInfo.attributes()+"test","Message");
The XML Contains the following format.
<Network xmlns="http://www.test.com/2005/test/omc/conf"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.test.com/2005/test/omc/conf/TestConfigurationEdition3proposal4.xsd">
<TestDomain>
<WAC>
<!--Release Parameter -->
<Parameters ParameterName="ne_release" OutageType="None"
accessRight="CreateOnly" isMandatory="true"
Planned="false"
Reference="true" Working="true">
<DataType>
<StringType/>
</DataType>
<GUIInfo graphicalName="Release"
tabName="All"
description="Describes the release version of the managed object"/>
</Parameters>
</TestDomain>
</Network>
Any sample code how to parse this kind of xml file with namespaces...
Regards,
Purushothami have exactly the same problem with KXml2, but using a j2me-polish netbeans project.
i've tried to work around with similar ways like you, but none of them worked. now i've spent 3 days for solving this problem, i'm a bit disappointed :( what is wrong with setting the downloaded kxml2 jar path in libraries&resources?
screenshot
Maybe you are looking for
-
Procedures with PL/SQL tables.
Hi, I want to write the procedures with pl/sql tables. Can we write if yes can you provide the example or hint. If a person helps me i will be great thank ful. thanks. null
-
Ipod 5th generation screen is white and black
I can't see my music selections or any memu items (i.e. music, artists, song names, albums, etc). The screen is white on the left 3rd and grey/blackish on the right 3rd. I can hear music out of the headphones so I know that is working, but can't see
-
Compared to Word, the spell check is very weak. Am I missing something?
I am attempting to switch from Word to Pages but I find the spell check is very weak. Am I missing something?
-
Sharepoints - Can't see external drive
Hi all, I've created a normal share for my external HDD (root directory) and turned on AFS and SMB sharing, "Update share" and a quick restart to make sure it took. I can't see my external HDD when connecting from another computer. Any idea what I ma
-
Hi Experts, I have some data targets in BW ( we are using 3.5 version) now i need to find out total queries on each data target? is there any specific T.code in BW. Plz help me on this? Thanks in advance David