Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Help requested: XML / XSD confusion - "prefix must resolve to a namespace" exception...

Reply
Thread Tools

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

 
 
Thea
Guest
Posts: n/a
 
      09-04-2006
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 xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xmlnsd="uri:myUri.com">
<xsd:simpleType name="pd:width">
<xsd:restriction base="xsdositiveInteger">
<xsd:maxLength value="4"/>
<xsd:minInclusive value="20"/>
<xsd:maxInclusive value="2000"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="pd:height">
<xsd:restriction base="xsdositiveInteger">
<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.XPathStylesheetDOM3Excepti on: Prefix must
resolve to a namespace: xsd

When I'm defining parameter types to be xsdositiveInteger, 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 ^^

 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      09-04-2006
In article < om>,
Thea <> wrote:

><?xml version="1.0"?>
><xsd:schema xmlnssd="http://www.w3.org/2001/XMLSchema"
> xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> xmlnsd="uri:myUri.com">
> <xsd:simpleType name="pd:width">


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

-- Richard
 
Reply With Quote
 
 
 
 
Thea
Guest
Posts: n/a
 
      09-05-2006
> 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 xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xmlnsd="uri:myUri.com" targetNamespace="uri:myUri.com">
and then:
<xsd:simpleType name="width">
<xsd:restriction base="xsdositiveInteger">
<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='pdositiveInt']
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?

 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      09-05-2006
In article < m>,
Thea <> wrote:

>To be precize changed previous exception into
>java.lang.NullPointerException: XPath query: *[@name='pdositiveInt']
>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
 
Reply With Quote
 
Thea
Guest
Posts: n/a
 
      09-05-2006
Whole document I'm using is:

<?xml version="1.0"?>
<xsd:schema xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xmlnsd="uri:myUri.com" targetNamespace="uri:myUri.com">
<xsd:simpleType name="positiveInt">
<xsd:restriction base="xsdositiveInteger">
<xsd:maxLength value="5"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="width">
<xsd:restriction base="xsdositiveInteger">
<xsd:maxLength value="4"/>
<xsd:minInclusive value="20"/>
<xsd:maxInclusive value="2000"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="height">
<xsd:restriction base="xsdositiveInteger">
<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

 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      09-05-2006
In article <edjkm4$1i9s$>,
Richard Tobin <> wrote:

>>java.lang.NullPointerException: XPath query: *[@name='pdositiveInt']
>>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
 
Reply With Quote
 
Thea
Guest
Posts: n/a
 
      09-06-2006

Richard Tobin napisal(a):
> In article <edjkm4$1i9s$>,
> Richard Tobin <> wrote:
>
> >>java.lang.NullPointerException: XPath query: *[@name='pdositiveInt']
> >>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


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 xmlnssd="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?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert XML to XSD? or DTD to XSD? Matt XML 3 09-11-2008 12:40 PM
src-resolve: Cannot resolve the name ... ivanet@gmail.com XML 1 03-23-2007 12:10 PM
Validation of XSD (XML Schema) against XSD Rushi XML 1 12-09-2005 08:12 AM
XML + XSD: Is it possible to get all errors against the XSD? Markus Java 1 11-22-2005 02:53 PM
XML schema - Make xsd include another xsd stiank81 XML 4 06-26-2005 05:11 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57