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

Discussion in 'XML' started by Thea, Sep 4, 2006.

  1. Thea

    Thea Guest

    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 ^^
     
    Thea, Sep 4, 2006
    #1
    1. Advertising

  2. In article <>,
    Thea <> wrote:

    ><?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
     
    Richard Tobin, Sep 4, 2006
    #2
    1. Advertising

  3. Thea

    Thea Guest

    > 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?
     
    Thea, Sep 5, 2006
    #3
  4. In article <>,
    Thea <> wrote:

    >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
     
    Richard Tobin, Sep 5, 2006
    #4
  5. Thea

    Thea Guest

    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 :)
     
    Thea, Sep 5, 2006
    #5
  6. In article <edjkm4$1i9s$>,
    Richard Tobin <> wrote:

    >>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
     
    Richard Tobin, Sep 5, 2006
    #6
  7. Thea

    Thea Guest

    Richard Tobin napisal(a):
    > In article <edjkm4$1i9s$>,
    > Richard Tobin <> wrote:
    >
    > >>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?
     
    Thea, Sep 6, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,167
    Markus
    Nov 22, 2005
  2. Matt
    Replies:
    3
    Views:
    37,305
    MKNDK
    Sep 11, 2008
  3. stiank81
    Replies:
    4
    Views:
    15,496
    stiank81
    Jun 26, 2005
  4. Rushi
    Replies:
    1
    Views:
    576
  5. Anna
    Replies:
    0
    Views:
    651
Loading...

Share This Page