Help requested: XML / XSD confusion - "prefix must resolve to a namespace" exception...

T

Thea

Hi
I am trying to use datatypes defined in xml file to check correctness
of input parameter values
To define needed datatypes following schema.xml file was created:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pd="uri:myUri.com">
<xsd:simpleType name="pd:width">
<xsd:restriction base="xsd:positiveInteger">
<xsd:maxLength value="4"/>
<xsd:minInclusive value="20"/>
<xsd:maxInclusive value="2000"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="pd:height">
<xsd:restriction base="xsd:positiveInteger">
<xsd:maxLength value="4"/>
<xsd:minInclusive value="20"/>
<xsd:maxInclusive value="2000"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>

When I'm trying to run program with types of parameters set to
pd:height and pd:width I get following exception:

org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must
resolve to a namespace: xsd

When I'm defining parameter types to be xsd:positiveInteger, everything
works fine
But if I only try to use prefix pd: I get that exception.

I went through stack trace but that led me nowhere...
I've used google, read quite a bit, but got to no satisfying
conclusions...
I'm new to xml, and got quite confused
Please help ^^
 
T

Thea

That's not how you define types. You specify a targetNamespace on
the schema element, and then use unprefixed values in "name" attributes.

Not sure if I understood corrrectly...
something like:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pd="uri:myUri.com" targetNamespace="uri:myUri.com">
and then:
<xsd:simpleType name="width">
<xsd:restriction base="xsd:positiveInteger">
<xsd:maxLength value="4"/>
<xsd:minInclusive value="20"/>
<xsd:maxInclusive value="2000"/>
</xsd:restriction>
</xsd:simpleType>
?

Such code helped a tiny bit...
To be precize changed previous exception into
java.lang.NullPointerException: XPath query: *[@name='pd:positiveInt']
failed.
I'm using third party library that actually gets data using
cachedXPath.eval(contextNode, query, namespaceNode);
or
XPathAPI.eval(contextNode, query, namespaceNode);
(depending if there is anything cached)
Independent which eval is used, it returns empty nodeset.
Not null, but empty nodeset, to which library reacts by sending null
upwards...
And whole code to crash...
Is there something about XPath I should know and didn't stumble upon
while googling?
 
R

Richard Tobin

Thea said:
To be precize changed previous exception into
java.lang.NullPointerException: XPath query: *[@name='pd:positiveInt']
failed.

That doesn't appear to have anything to do with schemas. You haven't
shown us the document you're querying, so I can't tell what the problem
is.

-- Richard
 
T

Thea

Whole document I'm using is:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pd="uri:myUri.com" targetNamespace="uri:myUri.com">
<xsd:simpleType name="positiveInt">
<xsd:restriction base="xsd:positiveInteger">
<xsd:maxLength value="5"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="width">
<xsd:restriction base="xsd:positiveInteger">
<xsd:maxLength value="4"/>
<xsd:minInclusive value="20"/>
<xsd:maxInclusive value="2000"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="height">
<xsd:restriction base="xsd:positiveInteger">
<xsd:maxLength value="4"/>
<xsd:minInclusive value="20"/>
<xsd:maxInclusive value="2000"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
That's about it... three datatypes defined :)
 
R

Richard Tobin

java.lang.NullPointerException: XPath query: *[@name='pd:positiveInt']
failed.
[/QUOTE]

I take it from your other message that you are querying the schema
document itself. In the schema you have

<xsd:simpleType name="positiveInt">

So you need to change your XPath to

*[@name='positiveInt']

because you don't have "pd:" on it any more.

-- Richard
 
T

Thea

Richard Tobin napisal(a):
java.lang.NullPointerException: XPath query: *[@name='pd:positiveInt']
failed.

I take it from your other message that you are querying the schema
document itself. In the schema you have

<xsd:simpleType name="positiveInt">

So you need to change your XPath to

*[@name='positiveInt']

because you don't have "pd:" on it any more.

-- Richard[/QUOTE]

Thanks, that solved this particular problem.

Now I'm back to 'prefix must resolve to a namespace' stuff, but...
In heap of messages issued by third party library I noticed debugging
statement like:

xmnls: null = http://www.w3.org/2001/XMLSchema

and in schema it says
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" (...)>

I know that thing uses 'lookupPrefix' method from org.w3c.dom.Node
class.
Shouldn't it return 'xsd' prefix?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top