Xml document parser
I have the java source code for a SAX compiler to parse my XML document.
To make this work I was told to include the following in my classpath: -
� j2sdk1.4.1_01/jaxp-1.1/jaxp.jar
� j2sdk1.4.1_01/jaxp-1.1/xalan.jar
� j2sdk1.4.1_01/jaxp-1.1/crimson.jar
by the way I have got j2sdk1.4.1_01!!
I have also got another java file which is a java class that calls my parser.java file. When I compile the java class file I get weird errors such as:
"Registry key 'Software\JavaSoft\Java Runtime Environment\CurrentVersion' has value '1.3', but '1.4' is required.
ERROR: could not find java.dll
ERROR: could not find Java 2 Runtime Environemnt.
This is the code for my java class:
import java.io.*;
import java.util.*;
public class testXML {
public static void main(final String[] pArgs) throws IOException {
new CustomerParser("flock.xml");
I'm pretty new to this parsing business, and Im really not sure what to do.
1)is it my java software playing up?
2)or is it my classpath?
3)or what?
hope someone can help, Jim.
Find the old version of java.exe that's running and get rid of it. (or remove the pathe entry)
Similar Messages
-
Hy is there anyway to specify a base dir when parsing a document? Have a doctype defined that references a XML file but the file is relative to the parsing document.
Example :
<!DOCTYPE something [
<!ENTITY fileRef SYSTEM "file:./util/otherFile.xml">
]>
<something>
&fileRef ;
</something>
When parsing this document i get the following exception "java.io.FileNotFoundException: ./util/otherFile.xml (The system cannot find the path specified)". Though the file is in the specified directory.
Another question i have is if it's possible to make any reference to any system environment variables from within an XML document.
Thanx,
Daniel CampeloYes, call the setSystemId() method on the InputSource you are giving to the parser. Remember you have to give it a URI, not a path name. (The File class has a method to return the URI of a file path.)
And sure, you can refer to system environment variables in an XML document. Just don't expect those things to be treated any differently than any other text. If you want them to be replaced by the value of the environment variables, for example, you have to do that yourself. -
Hello I am doing some SOAP XML stuff and I am having an issue that hopefully I can get some help with.
Is XML like this valid to do in a SOAP message?
<prompt>1 &_lt_; 0? <prompt>It's suppose to represent "1 < 0?"
* the forum formatter seems to eat up my encoded text and transofrms it into acutal "<" so I am placing underscores "_" everywhere to keep the text. so above is actually without underscores
From what I've read I think it is. I have text like this transported as part of the overall SOAP message to my client from the server.
In my code I do:
// Create an instance of the DocumentBuilderFactory
DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
// Get the DocumentBuilder from the factory
DocumentBuilder builder = documentFactory.newDocumentBuilder();
Document doc = builder.parse(inputStream);
...inputStream is an InputStream (specifically ByteArrayInputStream) containing the XML.
The issue I am having is that wherever I have an '&' (such as "&_lt_;" or "&_gt_;" or "&" etc...) the parsing seems to get cut off and the rest of the string doesn't seem to get parsed. So the above string "1 &_lt_; 0?" ends up being "1 ".
Also is there an easy way to get back or rebuild the XML into a string from a Document object? I would really like to do that right after I do the parse method and see if the XML data that the Document object has is the same as what's in the inputStream (which is "1 &_lt_; 0?").
Any input you can provide is much appreciated. Thanks,
LatemHello I am doing some SOAP XML stuff and I am having an issue that hopefully I can get some help with.
Is XML like this valid to do in a SOAP message?
<prompt>1 &_lt_; 0? <prompt>It's suppose to represent "1 < 0?"
* the forum formatter seems to eat up my encoded text and transofrms it into acutal "<" so I am placing underscores "_" everywhere to keep the text. so above is actually without underscores
From what I've read I think it is. I have text like this transported as part of the overall SOAP message to my client from the server.
In my code I do:
// Create an instance of the DocumentBuilderFactory
DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
// Get the DocumentBuilder from the factory
DocumentBuilder builder = documentFactory.newDocumentBuilder();
Document doc = builder.parse(inputStream);
...inputStream is an InputStream (specifically ByteArrayInputStream) containing the XML.
The issue I am having is that wherever I have an '&' (such as "&_lt_;" or "&_gt_;" or "&" etc...) the parsing seems to get cut off and the rest of the string doesn't seem to get parsed. So the above string "1 &_lt_; 0?" ends up being "1 ".
Also is there an easy way to get back or rebuild the XML into a string from a Document object? I would really like to do that right after I do the parse method and see if the XML data that the Document object has is the same as what's in the inputStream (which is "1 &_lt_; 0?").
Any input you can provide is much appreciated. Thanks,
Latem -
Hi,
when i am parsing the document having encoding scheme is US-ASCII
doc = docBuilder.parse(url);
it throws Exception :
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Byte "146" is not a member of the (7-bit) ASCII character set.
how can i resolve it ?Read url and convert the String to bytes using UTF-8, which is the default character encoding for XML.
-
Parse and output XML document while preserving attribute order
QUESTION: How can I take in an element with attributes from an XML and output the same element and attributes while preserving the order of those attributes?
The following code will parse and XML document and generate (practically) unchanged output. However, all attributes are ordered a-z
Example: The following element
<work_item_type work_item_db_site="0000000000000000" work_item_db_id="0" work_item_type_code="3" user_tag_ident="Step" name="Work Step" gmt_last_updated="2008-12-31T18:00:00.000000000" last_upd_db_site="0000000000000000" last_upd_db_id="0" rstat_type_code="1">
</work_item_type>is output as:
<work_item_type gmt_last_updated="2008-12-31T18:00:00.000000000" last_upd_db_id="0" last_upd_db_site="0000000000000000" name="Work Step" rstat_type_code="1" user_tag_ident="Step" work_item_db_id="0" work_item_db_site="0000000000000000" work_item_type_code="3">
</work_item_type>As you may notice, there is no difference in these besides order of the attributes!
I am convened that the problem is not in the stylesheet.xslt but if you are not then it is posted bellow.
Please, someone help me out with this! I have a feeling the solution is simple
The following take the XML from source.xml and outputs it to DEST_filename with attributes in a-z order
Code:
private void OutputFile(String DEST_filename, String style_filename){
//StreamSource stylesheet = new StreamSource(style_filename);
try{
File dest_file = new File(DEST_filename);
if(!dest_file.exists())
dest_file.createNewFile();
TransformerFactory tranFactory = TransformerFactory.newInstance();
Transformer aTransformer = tranFactory.newTransformer();
aTransformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
Source src = new DOMSource("source.xml");
Result dest = new StreamResult(dest_file);
aTransformer.transform(src, dest);
System.out.println("Finished");
catch(Exception e){
System.err.print(e);
System.exit(-1);
}You can't. The reason is, the XML Recommendation explicitly says the order of attributes is not significant. Therefore conforming XML serializers won't treat it as if it were significant.
If you have an environment where you think that the order of attributes is significant, your first step should be to reconsider. Possibly it isn't really significant and you are over-reaching in some way. Or possibly someone writing requirements is ignorant of this fact and the requirement can be discarded.
Or possibly your output is being given to somebody else who has a defective parser which expects the attributes to be in a particular order. You could quote the XML Recommendation to those people but often XML bozos are resistant to change. If you're stuck writing for that parser then you'll have to apply some non-XML processing to your output to fix it up on their behalf. -
Hi All,
We have a scenario of FTP-->PI---> Webservice. While triggering the data in the FTP, it is failing in the PI with the below error
SOAP: response message contains an error XIAdapter/PARSING/ADAPTER.SOAP_EXCEPTION - soap fault: Server was unable to read request. ---> There is an error in XML document (1, 447). ---> Input string was not in a correct format.
Can you please help?Hi Raja- It seems to be a data quality issue.
Check for the value @ 1447 position in the xml message that you are trying to send to web service..
may be a date filed/decimal value which is not in expected format. -
Hi folks,
I am using a cascaded mapping in my OM. I have a graphical mapping followed by the Java mapping. It is a flat file to IDOC mapping. Everything works fine in Dev but when I transport the same objects to QA, the Operation mapping though it doesn't fail in ESR testing tool, gives the following message and there is no output generated for the same payload which is successfully tested in DEV. Please advise on what could be the possible reasons.
Unable to display tree view; Error when parsing an XML document (Premature end of file.)kalyan,
There seems to be an invalid xml payload which causes this error in ESR not generating the tree view. Please find the similar error screenshot and rectify the payload.
Mutti -
Parsing an xml document inside a Thread
Hi Friends
I have to do some processing in my application for which i need to use multithreading.
Inside every new thread created i have to parse an xml document using s parsing tool like castor or jibx.
My question is that is it possible to parse a xml document inside a new thread everytime it gets created.
is it a good coding practice as it involves java code to do it.
Thanks
Vikengvikeng wrote:
Hi
Thanks for the reply.
Well i need to do some kind of a batch processing in my application.
I need to parse an xml document and upload the data i get after parsing into columns in the database.
Since its a batch what i was asking was is it possible to do it for every request as batch needs to handle hundreds of records during the daily or nightly sync.
Is it a good practice to do parsing for every record in a batch
Thanks
VikengI don't get it. One batch is one document, and that document contains e.g. 100 records? What's one request? A request for one batch? I would execute one batch in one thread.
Kaj -
Parseing an XML Document as a String
Hi all,
i am trying to parse an XML document to a parser. I get the file as a request parameter, which is filled in to at String variable.
But for some reason i get an SAXException, does anyone se the problem?
Thank you for your help...
Below is the code
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.text.*;
import java.net.*;
import java.net.URL;
import java.sql.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import javax.xml.parsers.*;
import javax.xml.transform.stream.StreamSource;
public class StartServlet extends HttpServlet
private boolean debug = true;
private final static String CONTENT = "content";
private final static String COOKIES = "cookies";
String resp = new String();
private static String NODE_TYPES[] = new String[] {
"ELEMENT",
"ATTRIBUTE",
"TEXT",
"CDATA_SECTION",
"ENTITY_REFERENCE",
"ENTITY",
"PROCESSING_INSTRUCTION",
"COMMENT",
"DOCUMENT",
"DOCUMENT_TYPE",
"DOCUMENT_FRAGMENT",
"NOTATION" };
public static void println(String s, int indent) {
for(int i = 0 ; i < indent; i++) {
System.out.println(" ");
System.out.println(s);
public static void println(String s) {
System.out.println(s);
public static void print(Node node){
printImpl(node, 0);
public static void printImpl(Node node, int indent){
if(node == null) {
return;
String nodeType = NODE_TYPES[node.getNodeType()];
String nodeName = node.getNodeName();
String nodeValue = node.getNodeValue();
if(nodeValue != null) {
nodeValue = nodeValue.trim();
if(nodeType.equals("TEXT") && nodeValue.equals("")) {
; //Ignore emty node
else {
println(nodeType + " - " + nodeName + " - " + nodeValue, indent);
NamedNodeMap attributes = node.getAttributes();
if (attributes != null) {
for(int i = 0; i < attributes.getLength(); i++) {
printImpl(attributes.item(i), indent + 1);
NodeList children = node.getChildNodes();
if(children != null) {
for(int i = 0; i < children.getLength(); i++){
printImpl(children.item(i), indent + 1);
public static DocumentBuilder newBuilder(boolean validation)
throws ParserConfigurationException {
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setValidating(validation);
domFactory.setNamespaceAware(true);
DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
//domBuilder.setErrorHandler(new PrintErrorHandler());
return domBuilder;
public static Document newDocument()
throws ParserConfigurationException{
DocumentBuilder domBuilder = newBuilder(false);
Document document = domBuilder.newDocument();
return document;
public static Document parse( String xml, boolean validation)
throws ParserConfigurationException, IOException, SAXException {
DocumentBuilder domBuilder = newBuilder(validation);
Document document = domBuilder.parse(xml);
return document;
public void init() {
public void service( javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) {
String[] cookies = null;
try{
Hashtable document = getDocument("http://.../first.xml", cookies);
resp = (String) document.get(CONTENT);
debug(resp);
print(parse(resp, false));
catch (SAXParseException e){
System.out.println("Saxfejl");
//System.exit(1);
catch (Exception e){
e.printStackTrace();
System.exit(1);
public void debug(String msg) {
if(debug) {
System.out.println(msg);
public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) {
try
// Insert user code from here.
catch(Throwable theException)
// uncomment the following line when unexpected exceptions
// are occuring to aid in debugging the problem.
//theException.printStackTrace();
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
performTask(request, response);
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
performTask(request, response);
private Hashtable getDocument(String urlCode, String[] oldCookies) {
Hashtable document = new Hashtable();
HttpURLConnection http = null;
try {
URL httpURL = new URL(urlCode);
// If HTTP Protocol, then open connection using the Request method indicated
URLConnection conn = httpURL.openConnection();
http = (HttpURLConnection) conn;
//http.setRequestMethod("GET");
http.setDoInput(true);
http.setDoOutput(true);
http.setUseCaches(false);
http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
if (oldCookies != null) {
for (int j = 0; j < oldCookies.length; j++) {
String cookie = oldCookies[j];
http.setRequestProperty("Cookie", cookie);
http.connect();
http.getContent();
StringBuffer tsb = new StringBuffer("");
if (http.getResponseCode() == 200) {
InputStream cis = http.getInputStream();
byte[] a = new byte[1024];
int n = cis.read(a);
while (n >= 0) {
tsb.append(new String(a, 0, n));
n = cis.read(a);
cis.close();
document.put(CONTENT, tsb.toString());
String[] cookies = null;
if (cookies == null) {
int headerFieldIndex = 0;
String headerFieldValue = http.getHeaderField(headerFieldIndex);
Vector cookieValues = new Vector();
while (headerFieldValue != null) {
String headerFieldName = http.getHeaderFieldKey(headerFieldIndex);
if ((headerFieldName != null) && headerFieldName.toLowerCase().equals("set-cookie")) {
int index = headerFieldValue.indexOf(";");
if (index > -1) {
headerFieldValue = headerFieldValue.substring(0, index);
cookieValues.addElement(headerFieldValue);
headerFieldValue = http.getHeaderField(++headerFieldIndex);
cookies = new String[cookieValues.size()];
cookieValues.copyInto(cookies);
document.put(COOKIES, cookies);
catch (Exception e) {
debug("url problem" + e);
finally {
if (http != null) {
http.disconnect();
return document;
}Hi,
Use this code it will helpful to you.
resultXMLDocument=(XmlDocument)documentDoc;
StringWriter sw = new StringWriter();
resultXMLDocument.write((Writer) sw);
xmlString=sw.toString();
thnaks,
suneel -
How to parse multiple xml documents from single buffer
Hello,
I am trying to use jaxb 2.0 to parse a buffer which contains multiple xml documents. However, it seems that it is meant to only parse a single document at a time and throws an exception when it gets to the 2nd document.
Is there a way I can tell jaxb to only parse the first complete document and not fetch the next one out of the buffer? Or what is the most efficient way to separate the buffer into two documents without parsing it manually. If I have to search the buffer for the next document root and then split the buffer, it seems like that defeats the purpose of using jaxb as the parser.
I am using the Unmarshaller.unmarshall method and the exception I am getting is:
org.xml.sax.SAXParseException: Illegal character at end of document, <.]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:476)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:198)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:167)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)
Thank you for your helpIt's just like any other XML parser, it's only designed to parse one XML document. If you have something that concatenates two XML documents together (that's what your "buffer" sounds like), then stop doing that.
-
No default attributes while Parsing XML document
Hellow.
I have such a problem:
I have XML document that uses XSD-schema.
In XSD-schema there is element that have two atributes:
<xsd:complexType name = "El1">
<xsd:attribute name = "atr1" xsd:default = "0" type = "xsd:boolean"/>
<xsd:attribute name = "atr2" default = "0" type = "xsd:boolean"/>
</xsd:complexType>And in XML document I write:
<El1 atr1 = "1"/>According to the XSD-schema parser must add to El1 second attribute "atr2" with its default value because it has default value. But when I do such a code:
factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
doc = builder.parse(new File("file1.xml"));
Element pEl;
pEl = doc.getDocumentElement()
NamedNodeMap Attribs = pEl.getAttributes();In the list of attributes "Attribs" - there is no attribute "attr1"!!!
What I have to do???Hello All
I am new to this parsing world. I have a doubt. I have an XML like
<xml>
<platform name = "windows">
<computer>
<hostname> hostname1 </hostname>
<IPAddress>127.0.3.03 </IPAddress>
</computer>
<computer>
<hostname> hostname2 </hostname>
<IPAddress>127.0.3.04 </IPAddress>
</computer>
</platform>
<platform name = "unix">
<computer>
<hostname> hostname6 </hostname>
<IPAddress>127.0.3.08 </IPAddress>
</computer>
<computer>
<hostname> hostname7 </hostname>
<IPAddress>127.0.3.09 </IPAddress>
</computer>
</platform>
</xml>
If i want to get details about individual computer under each platform as a string how do i do that?
Which parser would be ideal to be used DOM or SAX. -
How to parse XML document returned by webservices
Hi,
I have a form (version 10.1.2.0) which has to display the credit card types using webservices. I created the webstub and jar file through jdeveloper and then after adding the jar files in the respective classpaths, I import it in the forms. I write the code in when-button-pressed and it gives the result in xml document like this:
<?xml version="1.0" encoding="UTF-8"?><WSAnswerTO><error>false</error><errorMessage></errorMessage><
results><CardTypeTO><carTypId>3</carTypId><type>AMERICAN
EXPRESS</type><numLength>15</numLength><cvvLength>4</cvvLength><comments>1 800-639-0002</comments></CardTypeTO><CardTypeTO><carTypId>4</carTypId><type>DISCOVER</type><numLength>16</numLength><cvvLength>3</cvvLength><comments>1 800-347-2683</comments></CardTypeTO><CardTypeTO><carTypId>1</carTypId><type>MASTERCARD</type><numLength>16</numLength><cvvLength>3</cvvLength><comments>1 800-633-7367</comments></CardTypeTO><CardTypeTO><carTypId>2</carTypId><type>VISA</type><numLength>16</numLength><cvvLength>3</cvvLength><comments>1 800-945-2000</comments></CardTypeTO></results></WSAnswerTO>
From the above xml document, I only need to display the type (such as AMERICAN EXPRESS, VISA, ETC) in my forms. Can somebody please tell me how to do it. Do I need to store the values in a table first and then retrieve it. Please advise. I have already read a otn document in xml parsing but I didnt understand anything from it.
Please help. Thanks in advance.Hello,
It probably exists a database package/function to parse this kind of stuff.
If you want to keep the process into the Forms, here is a PL/SQL package you can use:
CREATE OR REPLACE PACKAGE Pkg_Tools AS
-- Types --
-- table of strings --
TYPE TYP_TAB_CHAR IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER;
-- Methodes --
-- function that return all contents for a given XML tag --
FUNCTION Get_Xml_Tag
PC$XmlContent IN VARCHAR2, -- XML string
PC$Tag IN VARCHAR2, -- searched tag
PC$NewLine IN VARCHAR2 DEFAULT CHR(10) -- defaull NL character
RETURN TYP_TAB_CHAR ;
END Pkg_Tools;
CREATE OR REPLACE PACKAGE BODY Pkg_Tools
IS
-- fonction de retour du contenu d'une balise XML --
FUNCTION Get_Xml_Tag
PC$XmlContent IN VARCHAR2, -- contenu XML
PC$Tag IN VARCHAR2, -- tag recherche
PC$NewLine IN VARCHAR2 DEFAULT CHR(10) -- defaull NL character
RETURN TYP_TAB_CHAR
IS
TC$Table TYP_TAB_CHAR ;
LC$Ligne VARCHAR2(32000) ;
LC$Xml VARCHAR2(32000) ;
LN$INDEX PLS_INTEGER := 0 ;
LN$TagDeb PLS_INTEGER ;
LN$TagFin PLS_INTEGER ;
LN$TagLength PLS_INTEGER ;
LN$LigLength PLS_INTEGER ;
LN$Occur PLS_INTEGER := 1 ;
BEGIN
IF ( PC$XmlContent IS NOT NULL AND PC$Tag IS NOT NULL ) THEN
LC$Xml := REPLACE( PC$XmlContent, CHR(13), '' ) ;
LN$TagLength := LENGTH( PC$Tag ) ;
LOOP
LN$TagDeb := INSTR( LC$Xml, PC$Tag, 1, LN$Occur ) ;
LN$TagFin := INSTR( LC$Xml, '</' || SUBSTR(PC$Tag,2, 256), 1, LN$Occur ) ;
LN$LigLength := (LN$TagFin - ( LN$TagDeb + LN$TagLength ) ) ;
IF (LN$TagDeb > 0 AND LN$TagFin > 0 ) THEN
LN$Occur := LN$Occur + 1 ;
LC$Ligne := SUBSTR( LC$Xml, LN$TagDeb + LN$TagLength, LN$LigLength ) ;
LOOP
LN$INDEX := LN$INDEX + 1 ;
LN$TagDeb := INSTR( LC$Ligne, PC$NewLine ) ;
IF LN$TagDeb > 0 THEN
IF Trim( SUBSTR( LC$Ligne, 1, LN$TagDeb - 1 )) IS NOT NULL THEN
TC$Table(LN$INDEX) := SUBSTR( LC$Ligne, 1, LN$TagDeb - 1 ) ;
ELSE
LN$INDEX := LN$INDEX - 1 ;
END IF ;
LC$Ligne := SUBSTR( LC$Ligne, LN$Tagdeb + LENGTH( PC$NewLine ), 30000 ) ;
ELSE
IF Trim(LC$Ligne) IS NOT NULL THEN
TC$Table(LN$INDEX) := LC$Ligne ;
END IF ;
EXIT ;
END IF ;
END LOOP ;
ELSE
EXIT ;
END IF ;
END LOOP ;
END IF ;
RETURN TC$Table ;
END Get_Xml_Tag ;
END Pkg_Tools;
/Then the call:
DECLARE
LC$t VARCHAR2(2000);
LT$Table Pkg_Tools.TYP_TAB_CHAR ;
BEGIN
lc$t := '<?xml version="1.0" encoding="UTF-8"?><WSAnswerTO><error>false</error><errorMessage></errorMessage><results>'
||'<CardTypeTO><carTypId>3</carTypId><TYPE>AMERICAN EXPRESS</TYPE><numLength>15</numLength><cvvLength>4</cvvLength>'
||'<comments>1 800-639-0002</comments></CardTypeTO><CardTypeTO><carTypId>4</carTypId><TYPE>DISCOVER</TYPE>'
||'<numLength>16</numLength><cvvLength>3</cvvLength><comments>1 800-347-2683</comments></CardTypeTO>'
||'<CardTypeTO><carTypId>1</carTypId><TYPE>MASTERCARD</TYPE><numLength>16</numLength><cvvLength>3</cvvLength>'
||'<comments>1 800-633-7367</comments></CardTypeTO><CardTypeTO><carTypId>2</carTypId><TYPE>VISA</TYPE>'
||'<numLength>16</numLength><cvvLength>3</cvvLength><comments>1 800-945-2000</comments></CardTypeTO></results></WSAnswerTO>' ;
LT$Table := Pkg_Tools.Get_Xml_Tag(LC$T,'<TYPE>') ;
IF LT$Table.COUNT > 0 THEN
FOR i IN LT$Table.First .. LT$Table.Last LOOP
dbms_output.put_line( 'Table(' || i || ')=' || LT$Table(i) ) ;
END LOOP ;
ELSE
dbms_output.put_line( 'tag xml not found' ) ;
END IF ;
END;Francois -
? is shown for Norwegian characters when XML document is parsed using DOM
Hi,
I've a sample program that creates a XML document with a single element book having Norwegian characters. Encoding is UTF-8. When i parse the XML document and try to access the value of that element then ? are shown for Norwegian characters. XML document file name is "Sample.xml"
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element root = doc.createElement("root");
root.setAttribute("value", "Á á Ą ą ä É é Ę");
doc.appendChild(root);
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
//create string from xml tree
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
StreamResult result = new StreamResult(baos);
DOMSource source = new DOMSource(doc);
trans.transform(source, result);
writeToFile("Sample.xml", baos.toByteArray());
InputSource is = new InputSource(new java.io.ByteArrayInputStream(readFile("Sample.xml")));
is.setEncoding("UTF-8");
DocumentBuilder obj_db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document obj_doc = obj_db.parse(is);
obj_doc.normalize();
System.out.println("Value is : " + new String(((Element) obj_doc.getElementsByTagName("root").item(0)).getAttribute("value").getBytes()));writeFile() - Writes the document bytes in Sample.xml file
readFile() - Reads the Sample.xml file
When i run this program XML editor shows the characters correctly but Java code output is: Á á ? ? ä É é ?
What's the problematic area in my java code. I didn't get any help from any source. Please suggest me the solution of this problem.
Thanx in advance.Hi,
I'm using JBuilder 2005 and i mentioned encoding UTF-8 for saving Java source files and also for compilation. I've modified my source code also. But the problem persists. After applying changing the dumped sample.xml file doesn't display these characters correctly in IE, but earlier it was displaying it correctly at IE.
Modified code is:
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element root = doc.createElement("root");
root.setAttribute("value", "Á á Ą ą ä É é Ę");
doc.appendChild(root);
OutputFormat output = new OutputFormat(doc, "UTF-8", true);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(baos, "UTF-8");
XMLSerializer s = new XMLSerializer(osw, output);
s.asDOMSerializer();
s.serialize(doc);
writeToFile("Sample5.xml", baos.toByteArray());
InputSource o = new InputSource(new java.io.ByteArrayInputStream(readFile("Sample5.xml")));
o.setEncoding("UTF-8");
com.sun.org.apache.xerces.internal.parsers.DOMParser obj_parser = new com.sun.org.apache.xerces.internal.parsers.DOMParser();
obj_parser.parse(o);
Document obj_doc = obj_parser.getDocument();
System.out.println("Value : " + new String(((Element) obj_doc.getElementsByTagName("root").item(0)).getAttribute("value").getBytes()));I'm hanged on this issue. Can u please provide me the code snippet that works with these characters or suggest solution.
Thanx -
Parse an Aggregate in XML Document using PL/SQL
Hi. I've been successful with parsing a TAG in XML Document stored in CLOB using PL/SQL XML Parser.
However, I need help on how to get the whole aggregate in XML Document stored in CLOB.
sample XML Doc :
<library>
<book>
<title>Oracle Complete Reference</title>
<author>Kevin</Author>
<year>2000</year>
</book>
<video>
<title>Learning C++</title>
<length>2 hours</length>
<video>
</library>
I need a function that will accept an Input which is the aggregate name and will return the aggregate value.
With the sample XML above, say the input is 'VIDEO', the function will return :
<video>
<title>Learning C++</title>
<length>2 hours</length>
<video>
I'll really appreciate any help.
nullI used such an example to parse several Varchar2 strings in a given DB session:
BEGIN
parser := xmlparser.newparser ;
xmlparser.parsebuffer(parser,xmlout) ;
domdoc := xmlparser.getDocument(parser) ;
xmlparser.FREEPARSER(parser) ;
parser.id := -1 ;
nodes := xslprocessor.selectNodes(
xmldom.makenode(domdoc),
'Positionen/Position') ;
for i in 1 .. xmldom.getLength(nodes) loop
node := xmldom.item(nodes,i-1) ;
-- do s/thing with the node
end loop ;
xmldom.freedocument(domdoc) ;
RETURN(komponenten) ;
EXCEPTION
WHEN OTHERS THEN
if parser.id <> -1 then xmlparser.freeparser(parser) ;
end if ;
if domdoc.id <> -1 then xmldom.freedocument(domdoc) ;
end if ;
RAISE ;
END ;
However, after about 2000 of nodes lists parsed, I get an ArrayIndexOutOfBoundsException from XMLNodeCover. Obviously, I should release the nodes or the nodelist, but I have not found any procedure to do this.
Pascal -
How to parse an XML document with oracle8i
Has anyone a good link or an example how to decode and store an XML document into an oracle8i database.
I' ve found only good things for oracle9i.
Thank you
RogerHere is an example of parsing xml taken fro Oracle8i 8.1.7 xdk.
This one uses external OS files to pase, but could be easily converted to
use CLOB or VARCHAR2 string for parsing XML documents.
IF you wanted to use CLOB to store and manipulate xml documents you can use XMLParser and XMLDom
packages along with the DBMS_LOB package to do that.
-- This file demonstates a simple use of the parser and DOM API.
-- The XML file that is given to the application is parsed and the
-- elements and attributes in the document are printed.
-- The use of setting the parser options is demonstrated.
set serveroutput on;
create or replace procedure domsample(dir varchar2, inpfile varchar2,
errfile varchar2) is
p xmlparser.parser;
doc xmldom.DOMDocument;
-- prints elements in a document
procedure printElements(doc xmldom.DOMDocument) is
nl xmldom.DOMNodeList;
len number;
n xmldom.DOMNode;
begin
-- get all elements
nl := xmldom.getElementsByTagName(doc, '*');
len := xmldom.getLength(nl);
-- loop through elements
for i in 0..len-1 loop
n := xmldom.item(nl, i);
dbms_output.put(xmldom.getNodeName(n) || ' ');
end loop;
dbms_output.put_line('');
end printElements;
-- prints the attributes of each element in a document
procedure printElementAttributes(doc xmldom.DOMDocument) is
nl xmldom.DOMNodeList;
len1 number;
len2 number;
n xmldom.DOMNode;
e xmldom.DOMElement;
nnm xmldom.DOMNamedNodeMap;
attrname varchar2(100);
attrval varchar2(100);
begin
-- get all elements
nl := xmldom.getElementsByTagName(doc, '*');
len1 := xmldom.getLength(nl);
-- loop through elements
for j in 0..len1-1 loop
n := xmldom.item(nl, j);
e := xmldom.makeElement(n);
dbms_output.put_line(xmldom.getTagName(e) || ':');
-- get all attributes of element
nnm := xmldom.getAttributes(n);
if (xmldom.isNull(nnm) = FALSE) then
len2 := xmldom.getLength(nnm);
-- loop through attributes
for i in 0..len2-1 loop
n := xmldom.item(nnm, i);
attrname := xmldom.getNodeName(n);
attrval := xmldom.getNodeValue(n);
dbms_output.put(' ' || attrname || ' = ' || attrval);
end loop;
dbms_output.put_line('');
end if;
end loop;
end printElementAttributes;
begin
-- new parser
p := xmlparser.newParser;
-- set some characteristics
xmlparser.setValidationMode(p, FALSE);
xmlparser.setErrorLog(p, dir || '/' || errfile);
xmlparser.setBaseDir(p, dir);
-- parse input file
xmlparser.parse(p, dir || '/' || inpfile);
-- get document
doc := xmlparser.getDocument(p);
-- Print document elements
dbms_output.put('The elements are: ');
printElements(doc);
-- Print document element attributes
dbms_output.put_line('The attributes of each element are: ');
printElementAttributes(doc);
-- deal with exceptions
exception
when xmldom.INDEX_SIZE_ERR then
raise_application_error(-20120, 'Index Size error');
when xmldom.DOMSTRING_SIZE_ERR then
raise_application_error(-20120, 'String Size error');
when xmldom.HIERARCHY_REQUEST_ERR then
raise_application_error(-20120, 'Hierarchy request error');
when xmldom.WRONG_DOCUMENT_ERR then
raise_application_error(-20120, 'Wrong doc error');
when xmldom.INVALID_CHARACTER_ERR then
raise_application_error(-20120, 'Invalid Char error');
when xmldom.NO_DATA_ALLOWED_ERR then
raise_application_error(-20120, 'Nod data allowed error');
when xmldom.NO_MODIFICATION_ALLOWED_ERR then
raise_application_error(-20120, 'No mod allowed error');
when xmldom.NOT_FOUND_ERR then
raise_application_error(-20120, 'Not found error');
when xmldom.NOT_SUPPORTED_ERR then
raise_application_error(-20120, 'Not supported error');
when xmldom.INUSE_ATTRIBUTE_ERR then
raise_application_error(-20120, 'In use attr error');
end domsample;
show errors;
Maybe you are looking for
-
? Photoshop Elements 8 Organizer won't open on Windows Vista ?
I installed Photoshop Elements 8 onto a Windows Vista computer and registered. The Organizer opened with broken thumbnails throughout and I could not update the thumbnails. Therefore, I closed the Organizer and opened it again, hoping it would clear
-
Note: I did try to install the plugin just to see what would happen. When I clicked on "Install Missing Plugin" the next page said plugin could not be found---install manually. I clicked on manual install button and was directed to Adobe Flash Player
-
Why am I getting an error in Time Machine?
I have been using Time Machine to an external hard drive with no issues however yesterday, I added to the list of disks to back up another external hard drive that incldues my iTunes library. Since this time, I have been getting an error each time T
-
Problems loading upgrade to flash player
Help needed! Every time I try and download the latest version of flash player (usually prompted when I can't watch videos on websites), it allows me to load it to 50% and then tells me to shut down internet explorer to complete the download. But even
-
Hi, I am looking for a user-exit or BADI that exists in transaction vl03n and vl02n. Thank you!