You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by chodnik <wx...@o2.pl> on 2009/01/12 09:47:08 UTC

getElementDeclaration returns null

I have some code like this:
DOMParser parser = new DOMParser();

		
parser.setProperty("http://apache.org/xml/properties/dom/document-class-name",
					"org.apache.xerces.dom.PSVIDocumentImpl");
			
parser.setFeature("http://apache.org/xml/features/validation/schema", true);

parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",
false);

I parse xml document as input stream:

<?xml version="1.0" encoding="utf-8"?>
<RootElement xmlns="http://www.example.org/testSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/testSchema D:\testSchema.xsd">    
</RootElement>

Then I can get psvi info from root in this way:
((ElementPSVI)document.getDocumentElement()).getElementDeclaration();

In the next step i create new node using createElementNS and I add this node
to the root node. I call 
document.normalizeDocument();
to set PSVI in child node but getElementDeclaration returns null all the
same.
I can fix it in this way:
validator.validate(new DOMSource(document), new DOMResult(document));
When I have this line it seems to work propely. getElementDeclaration is not
null.
The questin is why normalizeDocument does not update psvi info in new nodes?
What should I do to get psvi info without validation, only using
normalizeDocument?
			
-- 
View this message in context: http://www.nabble.com/getElementDeclaration-returns-null-tp21410587p21410587.html
Sent from the Xerces - J - Users mailing list archive at Nabble.com.


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


Re: getElementDeclaration returns null

Posted by chodnik <wx...@o2.pl>.
Thank you Michael. I have now this settings:
config.setParameter("validate", true);		
config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
config.setParameter("psvi", true);
Everything works! Method normalizeDocument validates data and sets PSVI to
all nodes.
-- 
View this message in context: http://www.nabble.com/getElementDeclaration-returns-null-tp21410587p21423027.html
Sent from the Xerces - J - Users mailing list archive at Nabble.com.


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


Re: getElementDeclaration returns null

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Try setting the "psvi" parameter to true as well.

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

chodnik <wx...@o2.pl> wrote on 01/12/2009 12:45:30 PM:

>
> I have set configuration listed below.
>
> DOMConfiguration config = document.getDomConfig();
>        config.setParameter("validate", true);
>        config.setParameter("infoset", true);
>        config.setParameter("schema-type",
"http://www.w3.org/2001/XMLSchema");
>        document.normalizeDocument();
>
> It still doesn't work.
> --
> View this message in context: http://www.nabble.
> com/getElementDeclaration-returns-null-tp21410587p21419641.html
> Sent from the Xerces - J - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org

Re: getElementDeclaration returns null

Posted by chodnik <wx...@o2.pl>.
I have set configuration listed below.

DOMConfiguration config = document.getDomConfig();
		 config.setParameter("validate", true);
		 config.setParameter("infoset", true);
		 config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
		 document.normalizeDocument();

It still doesn't work.
-- 
View this message in context: http://www.nabble.com/getElementDeclaration-returns-null-tp21410587p21419641.html
Sent from the Xerces - J - Users mailing list archive at Nabble.com.


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


Re: getElementDeclaration returns null

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
chodnik <wx...@o2.pl> wrote on 01/12/2009 09:34:30 AM:

> I've found how use normalizeDocument in this article:
>
> http://www.idealliance.
> org/papers/dx_xmle04/papers/02-05-02/02-05-02.html#d0e1114
>
> Now I set
> document.getDomConfig().setParameter("infoset", true);
> but there is no changes, getElementDeclaration still returns null.
> I think normalizeDocument method validates document in memory every time
I
> call it. Is this a bug? I use Xerces 2.9.1.

"infoset" has nothing to do with schema validation. Please review the
available parameters [1] in the spec. At the very least you should be
setting "schema-type" and "validate".

> --
> View this message in context: http://www.nabble.
> com/getElementDeclaration-returns-null-tp21410587p21415588.html
> Sent from the Xerces - J - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org

Thanks.

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

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

Re: getElementDeclaration returns null

Posted by chodnik <wx...@o2.pl>.
I've found how use normalizeDocument in this article:

http://www.idealliance.org/papers/dx_xmle04/papers/02-05-02/02-05-02.html#d0e1114

Now I set
document.getDomConfig().setParameter("infoset", true);
but there is no changes, getElementDeclaration still returns null.
I think normalizeDocument method validates document in memory every time I
call it. Is this a bug? I use Xerces 2.9.1.
-- 
View this message in context: http://www.nabble.com/getElementDeclaration-returns-null-tp21410587p21415588.html
Sent from the Xerces - J - Users mailing list archive at Nabble.com.


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


Re: getElementDeclaration returns null

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
chodnik <wx...@o2.pl> wrote on 01/12/2009 03:47:08 AM:

<snip/>

> Then I can get psvi info from root in this way:
> ((ElementPSVI)document.getDocumentElement()).getElementDeclaration();
>
> In the next step i create new node using createElementNS and I add this
node
> to the root node. I call
> document.normalizeDocument();
> to set PSVI in child node but getElementDeclaration returns null all the
> same.
> I can fix it in this way:
> validator.validate(new DOMSource(document), new DOMResult(document));
> When I have this line it seems to work propely. getElementDeclaration is
not
> null.
> The questin is why normalizeDocument does not update psvi info in new
nodes?
> What should I do to get psvi info without validation, only using
> normalizeDocument?

PSVI [1] = post-schema-validation infoset. It is the result of schema
validation (or more accurately assessment [2]). If you want PSVI from
normalizeDocument() then you need to configure the DOMConfiguration so that
it performs schema validation.

> --
> View this message in context: http://www.nabble.
> com/getElementDeclaration-returns-null-tp21410587p21410587.html
> Sent from the Xerces - J - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org

Thanks.

[1] http://www.w3.org/TR/xmlschema-1/#key-psvi
[2] http://www.w3.org/TR/xmlschema-1/#key-va

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