XMLDocument.validateContent(DTD)
Hi, I use xmlparserv2.jar.
I have a case that is after I created a document use dom. I want
to check the validity of the document with an existing DTD. I
tried to use the method XMLDocument.validateContent(dtd).
However it is always returning true no matter how invalid the
dtd is. Maybe I understand the meaning incorrectly.
It would be very much appreciated for any help
My friend , if you are using Internet Explorer then your DTD
will not validate your data (it may wrong) don't know why but
it happens. I am also finding the reason and i am nearer to
that. as soon as i got the reason , i will mail you. for the
time being insted of that you can use "schema" to validate your
data.
Cheers
Similar Messages
-
XMLDocument.validateContent(schema) returns "Element not completed: 'null'"
Hello all. What differences between 2 XMLDocument's (created manually and through DOMParser) for XMLDocument.validateContent()? xmlparserv2.jar from Oracle 10.2.0.3.
import oracle.xml.parser.schema.XMLSchema;
import oracle.xml.parser.schema.XSDBuilder;
import oracle.xml.parser.v2.DOMParser;
import oracle.xml.parser.v2.XMLDocument;
import oracle.xml.parser.v2.XMLParseException;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import java.io.StringReader;
public class DomValidateTest {
public static void main(String[] args)
throws Exception {
// Schema
XSDBuilder builder = new XSDBuilder();
InputSource schemaSource = new InputSource(
new StringReader(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
" <xs:element name=\"root\" nillable=\"false\">\n" +
" <xs:complexType>\n" +
" <xs:sequence>\n" +
" <xs:element name=\"value\" type=\"xs:string\" nillable=\"false\"/>\n" +
" </xs:sequence>\n" +
" </xs:complexType>\n" +
" </xs:element>\n" +
"</xs:schema>"
XMLSchema schema = builder.build(schemaSource);
// First document
XMLDocument doc = new XMLDocument();
Element rootElement = doc.createElement("root");
doc.appendChild(rootElement);
rootElement.appendChild(doc.createElement("value"));
doc.print(System.out);
try {
doc.validateContent(schema);
System.out.println("document validation succeed.");
} catch (XMLParseException e) {
System.err.println("document validation error: " + e.getMessage());
// Second document
DOMParser parser = new DOMParser();
parser.parse(new StringReader("<root><value/></root>"));
XMLDocument doc2 = parser.getDocument();
doc2.print(System.out);
try {
doc2.validateContent(schema);
System.out.println("document2 validation succeed.");
} catch (XMLParseException e) {
System.err.println("document2 validation error: " + e.getMessage());
}Output:
<root>
<value/>
</root>
document validation error: Element not completed: 'null'
<root>
<value/>
</root>
document2 validation succeed.For validating an XML document with a schema
http://www.oracle.com/technology/pub/articles/vohra_xmlschema.html
Thanks but imho these examples shows how to validate XMLDocument during its creation. I already have XMLDocument and wish to validate it. -
Creating XMLDocuments and setting their DTD
Hello,
i am exporting java objects to XML. I can construct a DOM with a XMLDocument and using its print method export it.
What i was unable to do so far was setting the DTD of these documents.
If i construct a parser, parse the DTD and then get the DTD via
Document doc = parser.getDocument() and
DocType dtd = doc.getDocumentType() how
do i set the DTD of the freshly constructed XMLDocuments to use this one in order to be able to check the correctness of the documents using this DTD at a later time?
Thanks.
Regards,
DirkYour method of getting the DTD object is correct. However, we do not do any validation while creating the DOM tree
using the DOM APIs. So setting the DTD in the Document will not help in validating the DOM tree that is constructed.
The only way to validate an XML file is to parse the XML document using DOMParser or SAXParser.
Oracle XML Team
null -
How to get the content of a DTD ?
(i'm French, please excuse my English)
I'm trying to get the content of the DTD corresponding to the file "fic"
fic is like : "....../XXXXXX.xml"
and contains : <!DOCTYPE composants SYSTEM "test.dtd">
Here is my code :
org.w3c.dom.Document Doc = DBXML.newDocument();
Doc = DBXML.parse(fic);
//Doc is a correctly parsed Document
org.w3c.dom.DocumentType DT = Doc.getDoctype();
System.out.println(DT.getSystemId());
//echo : "test.dtd" so I think that DT is good
System.out.println(DT.getNodeType());
//Echo "10" ==> DocumentType Node
System.out.println(DT.getNotations().getLength());
//Echo "0" !!!!!!!!!
I can't figure why getNotations() can't give me the DTD definitions
Please tell me if I try to use a wrong way or if I missed something.
Thanks a lot ...getNotations() method returns Dtd NOTATIONS when the NOTATIONS are referenced in the DTD.
Dtd:
<!ELEMENT map (entry*) >
<!ELEMENT entry (#PCDATA)>
<!ATTLIST entry value NOTATION (n1|n2) #REQUIRED>
<!NOTATION n1 SYSTEM "n1-url">
<!NOTATION n2 SYSTEM "n2-url">
/* getNotation() returns NamedNodeMap*/
DocumentType docType=xmlDocument.getDoctype();
System.out.println(docType.getName());
NamedNodeMap nnm=docType.getNotations();
System.out.println((nnm.item(0)).getNodeName());
System.out.println((nnm.item(1)).getNodeName());
System.out.println(docType.getNotations().getLength());
Output:
map
n1
n2
2 -
Hello
I have several XML files and into this XML files there is not th DTD call.
i have another file, the DTD.
There is any method or code example for, without modify the XML files for including the DTD call, validate the XML againts one DTD?
thanksAlice (guest) wrote:
: Hi! I have obtained the v2 parser for java and the one for
plsql.
: I want to validate xml documents against a DTD file provided
by
: another program. I can't find any sample code that does setDTD
: for validation.
: Can you tell me how it can be done, please?
: Thanks in advance!
The method to set the DTD is setDoctype().
Stub code follows:
// Test using InputSource
parser = new DOMParser();
parser.setErrorStream(System.out);
parser.showWarnings(true);
FileReader r = new FileReader(args[0]);
InputSource inSource = new InputSource(r);
inSource.setSystemId(createURL(args[0]).toString());
parser.parseDTD(inSource, args[1]);
dtd = (DTD)parser.getDoctype();
r = new FileReader(args[2]);
inSource = new InputSource(r);
inSource.setSystemId(createURL(args[2]).toString());
parser.setDoctype(dtd);
parser.setValidationMode(true);
parser.parse(inSource);
doc = (XMLDocument)parser.getDocument();
doc.print(new PrintWriter(System.out));
Oracle XML Team
http://technet.oracle.com
Oracle Technology Network
null -
Getting the entire DTD in the output file
Hi All,
I have a program that takes an XML file(has DTD and XML in the same file) as input. After parsing it, the output is written into a specified file. The output has first few lines of the DTD and the entire XML part, but is not having the ELEMENT and ATTLIST lines of the DTD.
My code runs like this:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
db.setErrorHandler(new CustomErrorHandler());
doc = db.parse(inFile);
XmlDocumentxDoc = (XmlDocument) doc;
xDoc.write(new PrintWriter(fos));
TIA,
sriThe standard parsers don't seem to do a very good job with DTDs. I've used a package at
http://www.wutka.com/dtdparser.html
to build DTDs. I haven't found a better way to get an internal DTD into an XML document than to separately convert both to String and manually insert the DTD (with appropriate DOCTYPE, etc.) into the XML. -
Not able to validate the xml document against DTD using SAX
Hi ,
i am not able to validate xml document against its DTD using SAX parser even after setting setValidating = true. even if the file is not correct according to DTD , it is not throwing any exception. what could be the reason.? please help..
kranthi
this is the code sample i used.
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
try {
factory.newSAXParser().parse(new File("sample.xml"), handler);
} catch (SAXException e) {
e.printStackTrace(); System.exit(2);
} catch (ParserConfigurationException e) {
e.printStackTrace();
}Hi karthik
Thanks for your response
Actually iam a beginner in java coding hence struggling to come up with the things
I tried putting your code and onserver side i see it is returning 09:12:17,234 INFO [STDOUT] [root: null]
actually the same program i wrote in java
and the same method i was calling from the main
and it is working fine and the xml document is getting displayed one important thing to be noted here is that the factory.newDocumentBuilder().parse(new File(filename));is returing XmlDocument
and the printing takes place
but the in same method public static Document parseXMLFile(String filename, boolean b) in servlet
the line factory.newDocumentBuilder().parse(new File(filename)); is returning DeferredDocumentImpl
and this creating problem , had it returned XmlDocument
i would have printed the elements one one
but as it is returning deferredimpl
iam unable to print the elements
could you please tell me why factory.newDocumentBuilder().parse(new File(filename)); is returning DeferredDocumentImpl
in servlets but in plain java pogram it is returing XmlDocument
Thanks
Bhanu -
UTF-8 Chacters Extracting from XMLDocument
I'm working on translating a string document that has utf-8 charcters within the text nodes, e.g. &lsquo &rsquo. In the original string these are 100% ok, and when represented through to a web page appear correctly as a left single and righ single quote.
However if i use the oracle.xml.parser.v2.DOMParser to create a oracle.xml.parser.v2.XMLDocument from the String, I cannot get the text from the nodes correctly, using oracle.xml.parser.v2.XMLDocument.print(System.out)
String xdoc =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" +
"<!DOCTYPE art SYSTEM \"simple.dtd\">" + "\n" +
"<art>ThisZZZ‘La Sapienza’ di Roma <b>stuff</b> ZZZZ‘La Sapienza’ di Roma. P.le Al 00185 ZZZZ" +
"</art>" + "\n";
XMLDocument xMLDocument = XMLHelper.parse(xdoc,masterBaseStyleUrl);
xMLDocument.print(System.out);
Results in
<?xml version = '1.0' encoding = 'UTF-8'?>
<!DOCTYPE art SYSTEM "simple.dtd">
<art>ThisZZZbLa Sapienzab di Roma <b>stuff</b> ZZZZbLa Sapienzab di Roma. P.le Al 00185 </art>
i've tried, org.w3c.dom.Node.getNodeValue() and others but they all corrupt the output.
Any help on accessing the original document values through the xmldocument would be great, i.e. the ‘ and &rsquo.
nullI'm working on translating a string document that has utf-8 charcters within the text nodes, e.g. &lsquo &rsquo. In the original string these are 100% ok, and when represented through to a web page appear correctly as a left single and righ single quote.
However if i use the oracle.xml.parser.v2.DOMParser to create a oracle.xml.parser.v2.XMLDocument from the String, I cannot get the text from the nodes correctly, using oracle.xml.parser.v2.XMLDocument.print(System.out)
String xdoc =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" +
"<!DOCTYPE art SYSTEM \"simple.dtd\">" + "\n" +
"<art>ThisZZZ‘La Sapienza’ di Roma <b>stuff</b> ZZZZ‘La Sapienza’ di Roma. P.le Al 00185 ZZZZ" +
"</art>" + "\n";
XMLDocument xMLDocument = XMLHelper.parse(xdoc,masterBaseStyleUrl);
xMLDocument.print(System.out);
Results in
<?xml version = '1.0' encoding = 'UTF-8'?>
<!DOCTYPE art SYSTEM "simple.dtd">
<art>ThisZZZbLa Sapienzab di Roma <b>stuff</b> ZZZZbLa Sapienzab di Roma. P.le Al 00185 </art>
i've tried, org.w3c.dom.Node.getNodeValue() and others but they all corrupt the output.
Any help on accessing the original document values through the xmldocument would be great, i.e. the ‘ and &rsquo.
null -
I get the error above when doing the following
import oracle.xml.parser.v2.DOMParser;
public class testXMLI do not know how do you pass the JDK compiler.Typos in the transcription process. I was more interested in showing my approach rather than precise code (apologies).
Actual code below - less 2 methods I have not changed.
Andrew
=======================
import java.net.URL;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.NamedNodeMap;
//import oracle.xml.parser.v2.DOMParser;
//import oracle.xml.parser.v2.XMLDocument;
import java.io.*;
import org.xml.sax.*;
import org.apache.xerces.parsers.DOMParser;
public class DOMSample
static public void main(String[] argv)
try
if (argv.length != 1)
// Must pass in the name of the XML file.
System.err.println("Usage: java DOMSample <xml file>");
System.exit(1);
// Get an instance of the parser
DOMParser parser = new DOMParser();
// Oracle's Way - gives an error "Error opening external DTD"
// Set various parser options: validation on,
// warnings shown, error stream set to stderr.
// parser.setErrorStream(System.err);
// parser.setValidationMode(DOMParser.DTD_VALIDATION); <-- deprecated ??
// parser.showWarnings(true);
// Parse the document
// System.out.println("Parsing XML document and do DTD Validation...");
// System.err.println("Parser version " + parser.getReleaseVersion());
// parser.parse(DemoUtil.createURL(argv[0]));
// My way - using Xerces - works, using an input source with Oracle way also fails
File file = new File ("c:\\temp2\\javFilterDat.xml");
InputSource is = new InputSource( new FileReader(file));
is.setSystemId("file:/c:"+ System.getProperty("file.separator") +
"temp2");
parser.parse(is);
// Obtain the document.
Document doc = parser.getDocument();
// Print document elements
System.out.print("The elements are: ");
printElements(doc);
// Print document element attributes
System.out.println("The attributes of each element are: ");
printElementAttributes(doc);
catch (Exception e)
System.out.println(e.toString()); -
Regarding validating XML against DTD
hello,
In my project I am receiving xml via HTTP post request
and this XML needs to be validated against a DTD in a remote server.
e.g. assume the xml to be
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE PUSH SYSTEM "http:\\whatever:xx\whatever\sms.dtd">
<PUSH ICP="Partenaire" ADM="UtilisateurChezPartenaire" VERSION="1.0">
</PUSH>
the java code uses Xerces parser
DOMParser parser = new DOMParser();
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setProperty(
"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
"http:\\whatever:xx\whatever\sms.dtd"");
parser.parse("c://localcopy/sms.xml");this Works fine.
But in some case I receive xml file without any !DOCTYPE declaration
(but is still needs to be validated against the same DTD as its mentioned in the business rules)
in such case how can the XML be validated against the DTD.
am I extected to add the
<!DOCTYPE PUSH SYSTEM "http:\\whatever:xx\whatever\sms.dtd">
to every XML via some XSLT script or is there a direct way of
validating a xml that has no DOCTYPE reference to a DTD
(the assumption is the DTD location is known beforehand)ok, i managed to solve the problem my self, using Transformer makes the job easier.
here is the code for anyone who might run into the same problem.#
public void whatEver(){
try{
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document xmlDocument = dBuilder.parse(new FileInputStream("c://a.xml"));
DOMSource source = new DOMSource(xmlDocument);
//StringWriter writer = new StringWriter();
StreamResult result = new StreamResult("c://a.xml");
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "./transformations/Push_Gateway.dtd");
//TransformerFactory transformerFactory = TransformerFactory.newInstance();
//Transformer newtransformer = transformerFactory.newTransformer();
transformer.transform(source, result);
catch(Exception e){
e.printStackTrace();
}the above code reads the a.xml file and adds/removes the DOCTYPE as specified in the transformer.setOutputProperty method and the same xml file is updated, this way different DTD could be referenced by the same xml and validated. this saves the process of adding/removing DOCTYPE via xslt. -
Appending a DocumentFragment to XMLDocument
I've been having a surprisingly difficult time trying to do this simple thing: append a DocumentFragment to an XMLDocument.
Here is my method; there are several print statements in here for debugging:
* This method joins two XML elements to form a single XML document: the individual
* SDI element, in an XMLDocument, and the non-SDI parts of the record, in a
* DocumentFragment. The method assumes that each element has just one child node
* containing the value. Also assumed is a class object, inputroot, which is a
* Node that is the root element of an XMLDocument.
private void joinSDI(XMLDocument sdidoc, DocumentFragment frag)
NodeList nonSdiNodeList = frag.getChildNodes();
Node tempRecRoot = sdidoc.getDocumentElement();
if (DEBUG3)
System.out.println("length of node list = "+nonSdiNodeList.getLength());
for (int i = 0; i < nonSdiNodeList.getLength(); i++)
System.out.println("iteration "+i);
Node node = nonSdiNodeList.item(i);
Node n = node.getFirstChild(); // this is the SDI
System.out.println("source name = " + node.getNodeName());
System.out.println("source value = " + n.getNodeValue());
Node tempNode = sdidoc.createTextNode(n.getNodeName());
tempNode.setNodeValue(n.getNodeValue());
System.out.println("new node type = " + tempNode.getNodeType());
System.out.println("new node name = " + tempNode.getNodeName());
System.out.println("new node value = " + tempNode.getNodeValue());
tempRecRoot.appendChild(tempNode);
// Now append this record XML doc to the insertion document we are building.
System.out.println("the constructed input doc:");
try {
sdidoc.print(System.out);
catch (IOException e)
System.out.println("Caught IO parse exception : "+e.getMessage());
this.inputroot.appendChild(sdidoc);
return;
Here is the input xml doc:
<?xml version="1.0" encoding="US-ASCII" standalone="no"?>
<!DOCTYPE hydro SYSTEM "hydro.dtd">
<hydro>
<ROW num="1">
<HM_SITE_CODE>HDMLC</HM_SITE_CODE>
<HM_PCODE>TRACE</HM_PCODE>
<DATE_HOUR>14-APR-00 12:00:00</DATE_HOUR>
<VALUE>644.039978</VALUE>
<SOURCE_ID>4</SOURCE_ID>
<VALIDATION>Z</VALIDATION>
</ROW>
<ROW num="2">
<HM_SITE_CODE>HDMLC</HM_SITE_CODE>
<HM_PCODE>TRACE</HM_PCODE>
<DATE_HOUR>14-APR-00 13:00:00</DATE_HOUR>
<VALUE>111</VALUE>
<SOURCE_ID>4</SOURCE_ID>
<VALIDATION>Z</VALIDATION>
</ROW>
<ROW num="3">
<HM_SITE_CODE>HDMLC</HM_SITE_CODE>
<HM_PCODE>TRACE</HM_PCODE>
<DATE_HOUR>14-APR-00 14:00:00</DATE_HOUR>
<VALUE>333</VALUE>
<SOURCE_ID>4</SOURCE_ID>
<VALIDATION>Z</VALIDATION>
</ROW>
</hydro>
Here is what I get for output (including the debugging statements):
nullI've been having a surprisingly difficult time trying to do this simple thing: append a DocumentFragment to an XMLDocument.
Here is my method; there are several print statements in here for debugging:
* This method joins two XML elements to form a single XML document: the individual
* SDI element, in an XMLDocument, and the non-SDI parts of the record, in a
* DocumentFragment. The method assumes that each element has just one child node
* containing the value. Also assumed is a class object, inputroot, which is a
* Node that is the root element of an XMLDocument.
private void joinSDI(XMLDocument sdidoc, DocumentFragment frag)
NodeList nonSdiNodeList = frag.getChildNodes();
Node tempRecRoot = sdidoc.getDocumentElement();
if (DEBUG3)
System.out.println("length of node list = "+nonSdiNodeList.getLength());
for (int i = 0; i < nonSdiNodeList.getLength(); i++)
System.out.println("iteration "+i);
Node node = nonSdiNodeList.item(i);
Node n = node.getFirstChild(); // this is the SDI
System.out.println("source name = " + node.getNodeName());
System.out.println("source value = " + n.getNodeValue());
Node tempNode = sdidoc.createTextNode(n.getNodeName());
tempNode.setNodeValue(n.getNodeValue());
System.out.println("new node type = " + tempNode.getNodeType());
System.out.println("new node name = " + tempNode.getNodeName());
System.out.println("new node value = " + tempNode.getNodeValue());
tempRecRoot.appendChild(tempNode);
// Now append this record XML doc to the insertion document we are building.
System.out.println("the constructed input doc:");
try {
sdidoc.print(System.out);
catch (IOException e)
System.out.println("Caught IO parse exception : "+e.getMessage());
this.inputroot.appendChild(sdidoc);
return;
Here is the input xml doc:
<?xml version="1.0" encoding="US-ASCII" standalone="no"?>
<!DOCTYPE hydro SYSTEM "hydro.dtd">
<hydro>
<ROW num="1">
<HM_SITE_CODE>HDMLC</HM_SITE_CODE>
<HM_PCODE>TRACE</HM_PCODE>
<DATE_HOUR>14-APR-00 12:00:00</DATE_HOUR>
<VALUE>644.039978</VALUE>
<SOURCE_ID>4</SOURCE_ID>
<VALIDATION>Z</VALIDATION>
</ROW>
<ROW num="2">
<HM_SITE_CODE>HDMLC</HM_SITE_CODE>
<HM_PCODE>TRACE</HM_PCODE>
<DATE_HOUR>14-APR-00 13:00:00</DATE_HOUR>
<VALUE>111</VALUE>
<SOURCE_ID>4</SOURCE_ID>
<VALIDATION>Z</VALIDATION>
</ROW>
<ROW num="3">
<HM_SITE_CODE>HDMLC</HM_SITE_CODE>
<HM_PCODE>TRACE</HM_PCODE>
<DATE_HOUR>14-APR-00 14:00:00</DATE_HOUR>
<VALUE>333</VALUE>
<SOURCE_ID>4</SOURCE_ID>
<VALIDATION>Z</VALIDATION>
</ROW>
</hydro>
Here is what I get for output (including the debugging statements):
null -
Hello,
In my application I need to perform some XML validation against an DTD file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Properties SYSTEM "MyFile.dtd">
<Properties>
<Property name="a" value="a1"/>
</Properties> Both XML file and the DTD are located in the same folder.
What I need, is to perform the XML validation against the DTD file from another location(more precisely, a DTD located in my application's jar) instead of the DTD from the same folder as XML file.
The reason for this is because the remote DTD file is most probably outdated.
This is how I do the validation curentlly:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(new org.xml.sax.ErrorHandler()
Document xmlDocument = builder.parse(destinationXMLFile.toURI().toString());
DOMSource source = new DOMSource(xmlDocument);
StreamResult result = new StreamResult(System.out);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "MyFile.dtd");
transformer.transform(source, result);Someone any idea?
Thanks,
johnnyUnusual but if you need this way your application just must to implement EntityResolver that always points to resource DTD.
[]s -
Appending a DocumentFragment to XMLDocument (acutal)
(Sorry for previous incorrect post, which was incomplete; this is the correct post.)
I've been having a surprisingly difficult time trying to do this simple thing: append a DocumentFragment to an XMLDocument.
Here is my method; there are several print statements in here for debugging:
* This method joins two XML elements to form a single XML document: the individual
* SDI element, in an XMLDocument, and the non-SDI parts of the record, in a
* DocumentFragment. The method assumes that each element has just one child node
* containing the value. Also assumed is a class object, inputroot, which is a
* Node that is the root element of an XMLDocument.
private void joinSDI(XMLDocument sdidoc, DocumentFragment frag)
NodeList nonSdiNodeList = frag.getChildNodes();
Node tempRecRoot = sdidoc.getDocumentElement();
if (DEBUG3)
System.out.println("length of node list = "+nonSdiNodeList.getLength());
for (int i = 0; i < nonSdiNodeList.getLength(); i++)
System.out.println("iteration "+i);
Node node = nonSdiNodeList.item(i);
Node n = node.getFirstChild(); // this is the SDI
System.out.println("source name = " + node.getNodeName());
System.out.println("source value = " + n.getNodeValue());
Node tempNode = sdidoc.createTextNode(n.getNodeName());
tempNode.setNodeValue(n.getNodeValue());
System.out.println("new node type = " + tempNode.getNodeType());
System.out.println("new node name = " + tempNode.getNodeName());
System.out.println("new node value = " + tempNode.getNodeValue());
tempRecRoot.appendChild(tempNode);
// Now append this record XML doc to the insertion document we are building.
System.out.println("the constructed input doc:");
try {
sdidoc.print(System.out);
catch (IOException e)
System.out.println("Caught IO parse exception : "+e.getMessage());
this.inputroot.appendChild(sdidoc);
return;
Here is the input xml doc:
<?xml version="1.0" encoding="US-ASCII" standalone="no"?>
<!DOCTYPE hydro SYSTEM "hydro.dtd">
<hydro>
<ROW num="1">
<HM_SITE_CODE>HDMLC</HM_SITE_CODE>
<HM_PCODE>TRACE</HM_PCODE>
<DATE_HOUR>14-APR-00 12:00:00</DATE_HOUR>
<VALUE>644.039978</VALUE>
<SOURCE_ID>4</SOURCE_ID>
<VALIDATION>Z</VALIDATION>
</ROW>
<ROW num="2">
<HM_SITE_CODE>HDMLC</HM_SITE_CODE>
<HM_PCODE>TRACE</HM_PCODE>
<DATE_HOUR>14-APR-00 13:00:00</DATE_HOUR>
<VALUE>111</VALUE>
<SOURCE_ID>4</SOURCE_ID>
<VALIDATION>Z</VALIDATION>
</ROW>
<ROW num="3">
<HM_SITE_CODE>HDMLC</HM_SITE_CODE>
<HM_PCODE>TRACE</HM_PCODE>
<DATE_HOUR>14-APR-00 14:00:00</DATE_HOUR>
<VALUE>333</VALUE>
<SOURCE_ID>4</SOURCE_ID>
<VALIDATION>Z</VALIDATION>
</ROW>
</hydro>
Here is what I get for output (including the debugging statements):
length of node list = 4
iteration 0
source name = DATE_HOUR
source value = 14-APR-00 12:00:00
new node type = 3
new node name = #text
new node value = 14-APR-00 12:00:00
iteration 1
source name = VALUE
source value = 644.039978
new node type = 3
new node name = #text
new node value = 644.039978
iteration 2
source name = SOURCE_ID
source value = 4
new node type = 3
new node name = #text
new node value = 4
iteration 3
source name = VALIDATION
source value = Z
new node type = 3
new node name = #text
new node value = Z
the constructed input doc:
<?xml version = '1.0'?>
<ROWSET><ROW num="1"><SITE_DATATYPE_ID>2158</SITE_DATATYPE_ID></ROW>14-APR-00 12:00:00644.0399784Z</ROWSET>
Exception in thread "main" java.lang.NullPointerException
at Hdbdom.joinSDI(Compiled Code)
at Hdbdom.addRec(Hdbdom.java:534)
at Hdbdom.buildInsertQry(Compiled Code)
at Hdbdom.parsedoc(Hdbdom.java:228)
at Hdbdom.main(Hdbdom.java:695)
I am puzzled by several things here:
- why i s the node name #text in the new document?
- why are my node values all jammed together in the output instead of becoming separate nodes?
- how do I set the doctype in the output document?
- why do I get a null pointer when attempting to append this output doc to the inputroot object?
Any help would be much appreciated,
--Rick Casey
nullpackage package2;
import oracle.xml.parser.v2.*;
import org.w3c.dom.*;
import java.io.*;
public class Class1
public static void main(String [] a) throws Throwable {
DOMParser d = new DOMParser();
d.parse(new StringReader("<x><y/><z/></x>"));
XMLDocument doc = d.getDocument();
DocumentFragment frag = doc.createDocumentFragment();
frag.appendChild(doc.createElement("extra-foo"));
appendFrag(doc,frag);
doc.print(System.out);
public static void appendFrag(XMLDocument doc, DocumentFragment frag) {
doc.getDocumentElement().appendChild(frag);
}<HR></BLOCKQUOTE>
Excellent! Thank you!
That worked, except that the fragment gets appended after the trailing </ROW> tag.
Here's an example of the incorrect append:
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1"> <SITE_DATATYPE_ID>2158</SITE_DATATYPE_ID>
</ROW>
<DATE_HOUR>14-APR-00 12:00:00</DATE_HOUR>
<VALUE>644.039978</VALUE>
<SOURCE_ID>4</SOURCE_ID>
<VALIDATION>Z</VALIDATION>
</ROWSET>
Is there an easy way to append such that my elements appear after the <SITE_DATATYPE_ID> element within the <ROW> tag?
TIA!
--Rick Caesy
<HR></BLOCKQUOTE>
Steve,
Nevermind my previous question; I answered it myself -- for those interested, the (very easy) solution was:
sdidoc.getDocumentElement().getFirstChild().appendChild(frag);
--Rick Casey -
DTD verification procedure/function in xmlgen package??
Is there a function or procedure in xmlgen package that verifies if the xmldocument is compliant with the DTD just like an error is generated if we use Java OracleXML putXML while using Java. Also, I am getting a system class not found (/oracle/rdbms/aurora/compiler) error when loading xmparser.jar file. Should I load the aurora.zip file first using the sys user in C:\oracle\ora81\javavm\lib directory ??
We can build Java Stored Procedures on Java Classes. If this is your case then the java source will not be visible in the USER_SOURCE view.
You can see what classes you have loaded in the schema (and whetehr you have the source for them) by running this query (warning: very slow!):
select name, source
from USER_JAVA_CLASSES
/Alternatively you can run this
select dbms_java.longname(object_name), object_type
from user_objects
where object_type like 'JAVA%'
/or join the two together...
select name, kind, source
from USER_JAVA_CLASSES
where name in ( select dbms_java.longname(object_name)
from user_objects
where object_type = 'JAVA SOURCE')
/Cheers, APC -
Getting DTD structure from Oracle DOMParser
I am having trouble getting DTD structure from DOMParser after I parse the xml file with external DTD.
When I do:
xmlDOMParser.parse(new FileInputStream(xmlFile));
XMLDocument xmlDoc=xmlDOMParser.getDocument();
DTD docType=xmlDOMParser.getDoctype();
NamedNodeMap nodeMap=docType.getElementDecls();
the nodeMap is equal to null.
I need to get the element structure of DTD, how can I do that?The below example is working fine for me
create table t1
as
select object_id id, object_name text
from all_objects;
Create table t2
as
select t1.*, 0 session_id
from t1
where 1=0;
CREATE OR REPLACE TYPE t2_type
AS OBJECT (
id number,
text varchar2(30),
session_id number
create or replace type t2_tab_type
as table of t2_type
create or replace
function parallel_pipelined( l_cursor in sys_refcursor )
return t2_tab_type
pipelined
parallel_enable ( partition l_cursor by any )
is
l_session_id number;
l_rec t1%rowtype;
begin
select sid into l_session_id
from v$mystat
where rownum =1;
loop
fetch l_cursor into l_rec;
exit when l_cursor%notfound;
-- complex process here
pipe row(t2_type(l_rec.id,l_rec.text,l_session_id));
end loop;
close l_cursor;
return;
end;
/And its getting executed in parallel
SQL> select DISTINCT session_id
2 from table(parallel_pipelined
3 (CURSOR(select /*+ parallel(t1) */ *
4 from t1 )
5 ))
6 ;
SESSION_ID
221
76
77
241
161
152
160
302
232
313
73
SESSION_ID
292
12 rows selected.But why its getting disconnected in my scenario. ???
Maybe you are looking for
-
Repeated Charges for auto-renew
Hello, Let's try this again. I have been charged 8 times today for autorenew @ $10 ea. I checked with PayPal and the charges are real. How do I contact Skype to get this reversed? I don't see anywhere to do it from within the app or the Web site.
-
Discoverer 4i & Applications 11i
Hello, i have just created a EUL for Oracle applications. I connect to discoverer with a username, password and responsability of applications user and i want to show in a worksheet what username and responsability are connected to discoverer. I have
-
I'm trying to resolve the name of a computer. This is the code I'm using now and it works: try{ InetAddress hostname[] = InetAddress.getAllByName(InetAddress.getLocalHost().getHostAddress() ) ; System.out.println(hostname[0].getHostName()); }
-
My unified mailbox stops updating automatically in Mail 5.1 (1251/1251.1). I can see the new mail icons in my individual email accounts, but the new emails will not appear until I change to a different mailbox or restart mail. Any fixes or suggestion
-
Data trasfer from maint. view to excel sheet
I have one maint. view , How to trasfer the data from that maint view to excel through bdc? Thanks, Regards, Vishal Bhagwat.