I have this problem that an xml instance is validated correctly
by xml tools, but not with my simple code, by setting the
validating flag to true.
--------------- Schema -----------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefa ult="qualified" xml:lang="EN"
targetNamespace ="http://www.mydomain.co m/demo/Test"
xmlns:test="htt p://www.mydomain.co m/demo/Test"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="TestO" type="test:Test Type"/>
<xs:complexTy pe name="TestType" >
<xs:sequence>
<xs:element name="Name" type="xs:string "/>
<xs:element name="Value" type="xs:intege r"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:schema>
---------------- Instance ----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<test:TestO xmlns:test="htt p://www.mydomain.co m/demo/Test"
xsi:schemaLocat ion="http://www.mydomain.co m/demo/Test
file:///home/csp/workspace/test-java/test.xsd"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" id="example-ncname">
<test:Name>stri ng</test:Name>
<test:Value>1 </test:Value>
</test:TestO>
This is validating correctly using XMLBuddy, XMLSpy, etc. But when
I try to do with the following code
DocumentBuilder Factory dbf = DocumentBuilder Factory.newInst ance();
dbf.setValidati ng(true);
DocumentBuilder db = dbf.newDocument Builder();
db.setErrorHand ler(new SimpleErrorHand ler());
Document document = db.parse(new
File("/home/csp/workspace/test-java/test.xml"));
It's reporting the errors
org.xml.sax.SAX ParseException: Document root element "test:TestO ", must
match DOCTYPE root "null".
at
org.apache.xerc es.util.ErrorHa ndlerWrapper.cr eateSAXParseExc eption(Unknown
Source)
at org.apache.xerc es.util.ErrorHa ndlerWrapper.er ror(Unknown Source)
at org.apache.xerc es.impl.XMLErro rReporter.repor tError(Unknown Source)
at org.apache.xerc es.impl.XMLErro rReporter.repor tError(Unknown Source)
at
org.apache.xerc es.impl.dtd.XML DTDValidator.ro otElementSpecif ied(Unknown
Source)
at
org.apache.xerc es.impl.dtd.XML DTDValidator.ha ndleStartElemen t(Unknown
Source)
at org.apache.xerc es.impl.dtd.XML DTDValidator.st artElement(Unkn own Source)
at
org.apache.xerc es.impl.XMLDocu mentFragmentSca nnerImpl.scanSt artElement(Unkn own
Source)
at
org.apache.xerc es.impl.XMLDocu mentScannerImpl $ContentDispatc her.scanRootEle mentHook(Unknow n
Source)
at
org.apache.xerc es.impl.XMLDocu mentFragmentSca nnerImpl$Fragme ntContentDispat cher.dispatch(U nknown
Source)
at
org.apache.xerc es.impl.XMLDocu mentFragmentSca nnerImpl.scanDo cument(Unknown
Source)
at org.apache.xerc es.parsers.XML1 1Configuration. parse(Unknown Source)
at org.apache.xerc es.parsers.XML1 1Configuration. parse(Unknown Source)
at org.apache.xerc es.parsers.XMLP arser.parse(Unk nown Source)
at org.apache.xerc es.parsers.DOMP arser.parse(Unk nown Source)
at org.apache.xerc es.jaxp.Documen tBuilderImpl.pa rse(Unknown Source)
at javax.xml.parse rs.DocumentBuil der.parse(Unkno wn Source)
at test.resolver.T estIdResolver.m ain(TestIdResol ver.java:36)
org.xml.sax.SAX ParseException: Document is invalid: no grammar found.
at
org.apache.xerc es.util.ErrorHa ndlerWrapper.cr eateSAXParseExc eption(Unknown
Source)
at org.apache.xerc es.util.ErrorHa ndlerWrapper.er ror(Unknown Source)
at org.apache.xerc es.impl.XMLErro rReporter.repor tError(Unknown Source)
at org.apache.xerc es.impl.XMLErro rReporter.repor tError(Unknown Source)
at
org.apache.xerc es.impl.dtd.XML DTDValidator.ha ndleStartElemen t(Unknown
Source)
at org.apache.xerc es.impl.dtd.XML DTDValidator.st artElement(Unkn own Source)
at
org.apache.xerc es.impl.XMLDocu mentFragmentSca nnerImpl.scanSt artElement(Unkn own
Source)
at
org.apache.xerc es.impl.XMLDocu mentScannerImpl $ContentDispatc her.scanRootEle mentHook(Unknow n
Source)
at
org.apache.xerc es.impl.XMLDocu mentFragmentSca nnerImpl$Fragme ntContentDispat cher.dispatch(U nknown
Source)
at
org.apache.xerc es.impl.XMLDocu mentFragmentSca nnerImpl.scanDo cument(Unknown
Source)
at org.apache.xerc es.parsers.XML1 1Configuration. parse(Unknown Source)
at org.apache.xerc es.parsers.XML1 1Configuration. parse(Unknown Source)
at org.apache.xerc es.parsers.XMLP arser.parse(Unk nown Source)
at org.apache.xerc es.parsers.DOMP arser.parse(Unk nown Source)
at org.apache.xerc es.jaxp.Documen tBuilderImpl.pa rse(Unknown Source)
at javax.xml.parse rs.DocumentBuil der.parse(Unkno wn Source)
at test.resolver.T estIdResolver.m ain(TestIdResol ver.java:36)
What's wrong with that code?
TIA 1 4283
Forget about this. Had to use "dbf.setAttribu te()" instead.
scorpion wrote: I have this problem that an xml instance is validated correctly by xml tools, but not with my simple code, by setting the validating flag to true.
--------------- Schema ----------------------------- <?xml version="1.0" encoding="UTF-8"?> <xs:schema elementFormDefa ult="qualified" xml:lang="EN" targetNamespace ="http://www.mydomain.co m/demo/Test" xmlns:test="htt p://www.mydomain.co m/demo/Test" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="TestO" type="test:Test Type"/> <xs:complexTy pe name="TestType" > <xs:sequence> <xs:element name="Name" type="xs:string "/> <xs:element name="Value" type="xs:intege r"/> </xs:sequence> <xs:attribute name="id" type="xs:ID"/> </xs:complexType> </xs:schema>
---------------- Instance ---------------------------------- <?xml version="1.0" encoding="UTF-8"?> <test:TestO xmlns:test="htt p://www.mydomain.co m/demo/Test" xsi:schemaLocat ion="http://www.mydomain.co m/demo/Test file:///home/csp/workspace/test-java/test.xsd" xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" id="example-ncname"> <test:Name>stri ng</test:Name> <test:Value>1 </test:Value> </test:TestO>
This is validating correctly using XMLBuddy, XMLSpy, etc. But when I try to do with the following code
DocumentBuilder Factory dbf = DocumentBuilder Factory.newInst ance(); dbf.setValidati ng(true); DocumentBuilder db = dbf.newDocument Builder(); db.setErrorHand ler(new SimpleErrorHand ler());
Document document = db.parse(new File("/home/csp/workspace/test-java/test.xml"));
It's reporting the errors
org.xml.sax.SAX ParseException: Document root element "test:TestO ", must match DOCTYPE root "null". at org.apache.xerc es.util.ErrorHa ndlerWrapper.cr eateSAXParseExc eption(Unknown Source) at org.apache.xerc es.util.ErrorHa ndlerWrapper.er ror(Unknown Source) at org.apache.xerc es.impl.XMLErro rReporter.repor tError(Unknown Source) at org.apache.xerc es.impl.XMLErro rReporter.repor tError(Unknown Source) at org.apache.xerc es.impl.dtd.XML DTDValidator.ro otElementSpecif ied(Unknown Source) at org.apache.xerc es.impl.dtd.XML DTDValidator.ha ndleStartElemen t(Unknown Source) at org.apache.xerc es.impl.dtd.XML DTDValidator.st artElement(Unkn own Source) at org.apache.xerc es.impl.XMLDocu mentFragmentSca nnerImpl.scanSt artElement(Unkn own Source) at org.apache.xerc es.impl.XMLDocu mentScannerImpl $ContentDispatc her.scanRootEle mentHook(Unknow n Source) at org.apache.xerc es.impl.XMLDocu mentFragmentSca nnerImpl$Fragme ntContentDispat cher.dispatch(U nknown Source) at org.apache.xerc es.impl.XMLDocu mentFragmentSca nnerImpl.scanDo cument(Unknown Source) at org.apache.xerc es.parsers.XML1 1Configuration. parse(Unknown Source) at org.apache.xerc es.parsers.XML1 1Configuration. parse(Unknown Source) at org.apache.xerc es.parsers.XMLP arser.parse(Unk nown Source) at org.apache.xerc es.parsers.DOMP arser.parse(Unk nown Source) at org.apache.xerc es.jaxp.Documen tBuilderImpl.pa rse(Unknown Source) at javax.xml.parse rs.DocumentBuil der.parse(Unkno wn Source) at test.resolver.T estIdResolver.m ain(TestIdResol ver.java:36) org.xml.sax.SAX ParseException: Document is invalid: no grammar found. at org.apache.xerc es.util.ErrorHa ndlerWrapper.cr eateSAXParseExc eption(Unknown Source) at org.apache.xerc es.util.ErrorHa ndlerWrapper.er ror(Unknown Source) at org.apache.xerc es.impl.XMLErro rReporter.repor tError(Unknown Source) at org.apache.xerc es.impl.XMLErro rReporter.repor tError(Unknown Source) at org.apache.xerc es.impl.dtd.XML DTDValidator.ha ndleStartElemen t(Unknown Source) at org.apache.xerc es.impl.dtd.XML DTDValidator.st artElement(Unkn own Source) at org.apache.xerc es.impl.XMLDocu mentFragmentSca nnerImpl.scanSt artElement(Unkn own Source) at org.apache.xerc es.impl.XMLDocu mentScannerImpl $ContentDispatc her.scanRootEle mentHook(Unknow n Source) at org.apache.xerc es.impl.XMLDocu mentFragmentSca nnerImpl$Fragme ntContentDispat cher.dispatch(U nknown Source) at org.apache.xerc es.impl.XMLDocu mentFragmentSca nnerImpl.scanDo cument(Unknown Source) at org.apache.xerc es.parsers.XML1 1Configuration. parse(Unknown Source) at org.apache.xerc es.parsers.XML1 1Configuration. parse(Unknown Source) at org.apache.xerc es.parsers.XMLP arser.parse(Unk nown Source) at org.apache.xerc es.parsers.DOMP arser.parse(Unk nown Source) at org.apache.xerc es.jaxp.Documen tBuilderImpl.pa rse(Unknown Source) at javax.xml.parse rs.DocumentBuil der.parse(Unkno wn Source) at test.resolver.T estIdResolver.m ain(TestIdResol ver.java:36)
What's wrong with that code?
TIA This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Will |
last post by:
I have been having problems validating an XForms document against the
XForms schema located at
http://www.w3.org/MarkUp/Forms/2002/XForms-Schema.xsd.
I have reduced the XForm to its bare bones as follows:
<?xml version="1.0" encoding="iso-8859-1"?>
<xf:model xmlns:xf="http://www.w3.org/2002/xforms">
<xf:instance xmlns=""/>
</xf:model>
|
by: Joel |
last post by:
Hi! I have a textbox and there is a validating. My question is when I quit
(Push Button) I don't want the validating proc to fire, is it possible?
|
by: Dale Strickland-Clark |
last post by:
A few days ago there was a discussion about which XML parser to use with
Python.
However, the discussion didn't cover validating parsers, at least, not
w3.org XML Schemas.
I looked into all the parsers that came up in the discussion but found no
mention of w3.org schemas.
It seems there are a few DTD validating parsers but that's all.
|
by: jean-gert nesselbosch |
last post by:
hello everybody,
does anybody know of standardization efforts concerning the output
of w3cSchema/relaxNG-validating parsers ?
I use libxml2 for validation-purposes (w3c-Schema and relaxNG) and have
the impression that
(a) the output in case the xml-document is not valid, is not very verbose
(b) the structure of the returned message (in case of the xml-document
|
by: Charles Law |
last post by:
Could someone please explain to me, in words of one syllable or less, how I
get the Validating event to fire for a form.
I have a form with one text box, and two buttons: OK and Cancel.
I have the OK button set as the AcceptButton and the Cancel button as the
.... well, you've guessed it.
I click OK and the form closes, without going to the Form1_Validating event.
I could validate in the Click event of the OK button, but I can't...
| |
by: Ian Jewitt |
last post by:
Hi,
I am having a problem where the validating event of a text box is not
always firing. I am using vb.net 2003.
I have an MDI application, one of the child forms contains a tab control
|
by: Darin |
last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to
handle textbox.validating, and I have the form setup so the Cancel
button is the Cancel button.
WHen the user clicks on the cancel button, the textbox.validating is
being called. I don't want it to be since they are exiting the screen
the validation doesn't have to be done.
How can I do that.
|
by: easoftware |
last post by:
I am using VS .Net 2003 and VB. I have an app with one parent and two
Mdi child forms. I need to validate data in the Mdi form. The
Form.Validating event works when I try to close a Mdi form, but not
when I try to switch form one Mdi form to the other. I tried to add
code to MdiForm1's Deactivate event:
Private Sub MidForm1_Deactivate(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Deactivate
Dim TempE As...
|
by: Al Santino |
last post by:
Hi,
It appears displaying a messagebox in a validating event will cancel the
subsequent event. In the program below, button 2's click event doesn't fire
if you open a dialog box in button 1's validating event. Am I doing
something wrong here?
Thanks
Al
Imports system
|
by: Hamed |
last post by:
Hello
I have a Data Entry Form having some controls including a TextBox. When the
user types an entry, I query a table and if it was entered before, I ask the
user (using ShowModal method of a custom message form) if he wants to see
his old entry in a new form. if he/she choose Yes, I create a new form and
show the previously entered data in it.
The problem is when I create and show the new form, the validating event is
fired two...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |