473,385 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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.XPathStylesheetDOM3Excepti on: 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 ^^

Sep 4 '06 #1
6 20768
In article <11********************@m73g2000cwd.googlegroups.c om>,
Thea <mo***************@gmail.comwrote:
><?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">
That's not how you define types. You specify a targetNamespace on
the schema element, and then use unprefixed values in "name" attributes.

-- Richard
Sep 4 '06 #2
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?

Sep 5 '06 #3
In article <11********************@e3g2000cwe.googlegroups.co m>,
Thea <mo***************@gmail.comwrote:
>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
Sep 5 '06 #4
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 :)

Sep 5 '06 #5
In article <ed***********@pc-news.cogsci.ed.ac.uk>,
Richard Tobin <ri*****@cogsci.ed.ac.ukwrote:
>>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
Sep 5 '06 #6

Richard Tobin napisal(a):
In article <ed***********@pc-news.cogsci.ed.ac.uk>,
Richard Tobin <ri*****@cogsci.ed.ac.ukwrote:
>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
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?

Sep 6 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: nico | last post by:
In my python scripts, I use a lot of accented characters as I work in french. In order to do this, I put the line # -*- coding: UTF-8 -*- at the beginning of the script file. Then, when I need...
5
by: cppaddict | last post by:
It is typical to put the line: using namespace std; at the top of a file which makes use of std library objects. To take a simple example: #include <iostream> using namespace std;
1
by: yanwan | last post by:
I met this problem in executing a c++ project in visual studio. Does anyone have suggestions to resolve "error lnk 2001"? --------------------Configuration: reconstruction - Win32...
5
by: SenthilSS | last post by:
My application produces XML Data files which have XML namespace qualified XML elements (nodes), but the namespace itself is not declared in the data file. My task is to read these data files in a...
3
by: beta | last post by:
Hello everyone, I need some help here. If anyone has encountered this, knidly give me your advice. I have a command button (Command0) and a listbox (List1). Upon clicking the command button,...
0
by: maxim mat | last post by:
Hi I need to build client for web service. But when I'm using Visual Studio .NET to add Web Reference, I get error: "Custom tool error: Unable to import WebService/Schema. Unable to import...
7
by: Jeff Lynn | last post by:
Help! I recently upgraded my VS V6 to VS 2005 and was unable to build projects that were perfectly ok under VS V6. Where VS 2005 fails was in the linker resolving external DLLs, which are Open...
3
by: raghunadhs | last post by:
Hi all, i have developed a ".dll" in vc++, regarding to find out CRC32. and in my V.B 6.0 application i am calling that .dll. If i run my v.b application it is working means.. i am able to find...
2
by: shalong | last post by:
Hi all, VS 2008 is complaining that HttpWebRequest class is not in System.Net namespace I have referenced System.Net and have coded "using System.Net" I think its a setup problem rather than a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.