You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Neil Delima <nd...@ca.ibm.com> on 2004/08/25 17:18:40 UTC

Re: Validate DOM document in memory using DOM level 3




Hi Mike,

See [1]

Mike Hao <mi...@yahoo.com> wrote on 08/25/2004 11:10:08 AM:

> I am trying to validate an in-memory DOM document using the DOM
> level 3 functionality. And I am following the instruction in this page:
>
> http://xml.apache.org/xerces2-j/faq-dom.html#domparser
>
> My questions are:
>
> 1. Do I have to create a LSParser?
Nope, it's not necessary to create an LSParser.

> 2. Which Document class should I use? The one in the dom3-xml-apis.jar
> or just the normal one?
org.w3c.dom.Document.

> 3. Where or How to get the APIs document of the DOM level 3
functionalities?
To build and access DOM Level 3 see [2].

[1] http://xml.apache.org/xerces2-j/faq-dom.html#faq-9
[2] http://xml.apache.org/xerces2-j/faq-dom.html#faq-6


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Help needed: cannot resolve symbol symbol : method getConfig ()

Posted by Mike Hao <mi...@yahoo.com>.
Hi,
 
I figured out the reason for the error I got. The name of the method getConfig() has been changed to getDomConfig().
 
Thanks,
 
Mike

Mike Hao <mi...@yahoo.com> wrote:

Hi there,

I am trying to use the DOM Level 3 functionalities. I checked out the xml-xerces source from the apach CVS, and built Xerces using the jars-dom3 target, and I got two new jar files: dom3-xml-apis.jar and the dom3-xercesImpl.jar. I included these new jars in my classpath and I run a testing program, but get some compiling error: 

C:\Temp>javac Test.java
Test.java:35: cannot resolve symbol
symbol  : method getConfig ()
location: interface org.w3c.dom.Document
                DOMConfiguration config = document.getConfig();
                                                  ^
Test.java:37: cannot resolve symbol
symbol  : method setDocumentURI (java.lang.String)
location: interface org.w3c.dom.Document
                document.setDocumentURI("file:///c:/data");
                        ^
Test.java:43: cannot resolve symbol
symbol  : method normalizeDocument ()
location: interface org.w3c.dom.Document
                document.normalizeDocument();
                        ^
3 errors

The following is my test code:

public class Test{

 public static void main(String[] args){

              Document document = null;

              String xmlFile = "file:///c:/data/personal.xml"; 

  try {
       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
       DocumentBuilder builder = factory.newDocumentBuilder();
       document = builder.parse(xmlFile);
   DOMConfiguration config = document.getConfig();
  
   document.setDocumentURI("file:///c:/data");
  
   config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
   config.setParameter("validate", Boolean.TRUE);
   config.setParameter("schema-location", "personal.xsd");
  
   document.normalizeDocument();

  } catch (FactoryConfigurationError e) {
       // unable to get a document builder factory
  } catch (ParserConfigurationException e) {
       // parser was unable to be configured
  } catch (SAXException e) {
       // parsing error
  } catch (IOException e) {
       // i/o error
  } 
  

 }

}

Can anyone tell me what's going wrong?

Thanks,

Mike

 

 

 


---------------------------------
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.
		
---------------------------------
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!

Help needed: cannot resolve symbol symbol : method getConfig ()

Posted by Mike Hao <mi...@yahoo.com>.
Hi there,

I am trying to use the DOM Level 3 functionalities. I checked out the xml-xerces source from the apach CVS, and built Xerces using the jars-dom3 target, and I got two new jar files: dom3-xml-apis.jar and the dom3-xercesImpl.jar. I included these new jars in my classpath and I run a testing program, but get some compiling error: 

C:\Temp>javac Test.java
Test.java:35: cannot resolve symbol
symbol  : method getConfig ()
location: interface org.w3c.dom.Document
                DOMConfiguration config = document.getConfig();
                                                  ^
Test.java:37: cannot resolve symbol
symbol  : method setDocumentURI (java.lang.String)
location: interface org.w3c.dom.Document
                document.setDocumentURI("file:///c:/data");
                        ^
Test.java:43: cannot resolve symbol
symbol  : method normalizeDocument ()
location: interface org.w3c.dom.Document
                document.normalizeDocument();
                        ^
3 errors

The following is my test code:

public class Test{

 public static void main(String[] args){

              Document document = null;

              String xmlFile = "file:///c:/data/personal.xml"; 

  try {
       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
       DocumentBuilder builder = factory.newDocumentBuilder();
       document = builder.parse(xmlFile);
   DOMConfiguration config = document.getConfig();
  
   document.setDocumentURI("file:///c:/data");
  
   config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
   config.setParameter("validate", Boolean.TRUE);
   config.setParameter("schema-location", "personal.xsd");
  
   document.normalizeDocument();

  } catch (FactoryConfigurationError e) {
       // unable to get a document builder factory
  } catch (ParserConfigurationException e) {
       // parser was unable to be configured
  } catch (SAXException e) {
       // parsing error
  } catch (IOException e) {
       // i/o error
  } 
  

 }

}

Can anyone tell me what's going wrong?

Thanks,

Mike

 

 

 

		
---------------------------------
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.

Namespace-Aware node question

Posted by Mike Hao <mi...@yahoo.com>.
Hi there,
 
I have an XML document and some schemas against to this document. I used a DOM parser read in this document and then tried to use the normalizeDocument() to revalidate this DOM object. I got fatal error says: 
 
NullLocalElementName: A null local name was encountered during namespace normalization of element
 
What's the cause reason of this error? What's does the namespace-aware node really mean?
 
Thanks,
 
Mike
 
 
 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: Validate DOM document in memory using DOM level 3

Posted by Mike Hao <mi...@yahoo.com>.
Hi Michael / All,
 
Thank you for your reply. I have successfully revalidate my in-memory DOM against a schema using the normalizeDocument() in my test progam.

>From the article:

http://www-106.ibm.com/developerworks/xml/library/x-keydom2.html
I know that if I want to use the revalidating feature of DOM level3, the node must be created using the namespace-aware method, like createElementNS(). But in my project, the code is already there, and the node is created using the Level 1 method, that is createElement(). I still want to use this new feature of DOM level 3, so is there any better way to by pass my problem? Or do you have any suggestions?
 
Thanks,
 
Mike

Michael Glavassevich <mr...@ca.ibm.com> wrote:

Hi Mike, 

Yes, you want to call normalizeDocument() but first you have setup the DOMConfiguration (see the 'schema-location', 'schema-type' and 'validate' parameters) [1] so that the DOM will be validated when this method is called. 

[1] http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#DOMConfiguration 

Mike Hao <mi...@yahoo.com> wrote on 08/25/2004 02:07:07 PM:

> Hi Neil, 
>   
> Thank you for your quick response. 
>   
> Which method should I use for this kind of validation? normalizeDocument()? 
>   
> Thanks, 
> Mike 
>   
> 
> Neil Delima <nd...@ca.ibm.com> wrote: 
> 
> 
> 
> 
> Hi Mike,
> 
> See [1]
> 
> Mike Hao wrote on 08/25/2004 11:10:08 AM:
> 
> > I am trying to validate an in-memory DOM document using the DOM
> > level 3 functionality. And I am following the instruction in this page:
> >
> > http://xml.apache.org/xerces2-j/faq-dom.html#domparser
> >
> > My questions are:
> >
> > 1. Do I have to create a LSParser?
> Nope, it's not necessary to create an LSParser.
> 
> > 2. Which Document class should I use? The one in the dom3-xml-apis.jar
> > or just the normal one?
> org.w3c.dom.Document.
> 
> > 3. Where or How to get the APIs document of the DOM level 3
> functionalities?
> To build and access DOM Level 3 see [2].
> 
> [1] http://xml.apache.org/xerces2-j/faq-dom.html#faq-9
> [2] http://xml.apache.org/xerces2-j/faq-dom.html#faq-6
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org

> Do you Yahoo!?
> New and Improved Yahoo! Mail - Send 10MB messages! 

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com 
E-mail: mrglavas@apache.org
		
---------------------------------
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!

Re: Validate DOM document in memory using DOM level 3

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mike,

Yes, you want to call normalizeDocument() but first you have setup the 
DOMConfiguration (see the 'schema-location', 'schema-type' and 'validate' 
parameters) [1] so that the DOM will be validated when this method is 
called.

[1] 
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#DOMConfiguration

Mike Hao <mi...@yahoo.com> wrote on 08/25/2004 02:07:07 PM:

> Hi Neil,
> 
> Thank you for your quick response. 
> 
> Which method should I use for this kind of validation? 
normalizeDocument()?
> 
> Thanks,
> Mike
> 
> 
> Neil Delima <nd...@ca.ibm.com> wrote:
> 
> 
> 
> 
> Hi Mike,
> 
> See [1]
> 
> Mike Hao wrote on 08/25/2004 11:10:08 AM:
> 
> > I am trying to validate an in-memory DOM document using the DOM
> > level 3 functionality. And I am following the instruction in this 
page:
> >
> > http://xml.apache.org/xerces2-j/faq-dom.html#domparser
> >
> > My questions are:
> >
> > 1. Do I have to create a LSParser?
> Nope, it's not necessary to create an LSParser.
> 
> > 2. Which Document class should I use? The one in the dom3-xml-apis.jar
> > or just the normal one?
> org.w3c.dom.Document.
> 
> > 3. Where or How to get the APIs document of the DOM level 3
> functionalities?
> To build and access DOM Level 3 see [2].
> 
> [1] http://xml.apache.org/xerces2-j/faq-dom.html#faq-9
> [2] http://xml.apache.org/xerces2-j/faq-dom.html#faq-6
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org

> Do you Yahoo!?
> New and Improved Yahoo! Mail - Send 10MB messages!

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Re: Validate DOM document in memory using DOM level 3

Posted by Mike Hao <mi...@yahoo.com>.
Hi Neil,
 
Thank you for your quick response. 
 
Which method should I use for this kind of validation? normalizeDocument()?
 
Thanks,
Mike
 

Neil Delima <nd...@ca.ibm.com> wrote:




Hi Mike,

See [1]

Mike Hao wrote on 08/25/2004 11:10:08 AM:

> I am trying to validate an in-memory DOM document using the DOM
> level 3 functionality. And I am following the instruction in this page:
>
> http://xml.apache.org/xerces2-j/faq-dom.html#domparser
>
> My questions are:
>
> 1. Do I have to create a LSParser?
Nope, it's not necessary to create an LSParser.

> 2. Which Document class should I use? The one in the dom3-xml-apis.jar
> or just the normal one?
org.w3c.dom.Document.

> 3. Where or How to get the APIs document of the DOM level 3
functionalities?
To build and access DOM Level 3 see [2].

[1] http://xml.apache.org/xerces2-j/faq-dom.html#faq-9
[2] http://xml.apache.org/xerces2-j/faq-dom.html#faq-6


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


		
---------------------------------
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!