Announcement Announcement Module
Collapse
No announcement yet.
XPath bug? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • XPath bug?

    Hi

    Is there a bug with NodeMapper and XPath? I have an XML document like this:

    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <inxdoc:inx-document xmlns="http://www.inx.com/ims/response/4.6"
        xmlns:inxdoc="http://www.inx.com/sd/document/4.6">
        <inxdoc:metadata>
            <inxdoc:doc-properties>
                <inxdoc:doc-property name="data-source">Blah</inxdoc:doc-property>
                <inxdoc:doc-property name="identifier">blah.txt</inxdoc:doc-property>
                <inxdoc:doc-property name="modified-date">Monday, November 1, 2004 7:17:10 PM GMT</inxdoc:doc-property>
                <inxdoc:doc-property name="title">blah.txt</inxdoc:doc-property>
                <inxdoc:doc-property name="extension">txt</inxdoc:doc-property>
                <inxdoc:doc-property name="content-type">text/plain</inxdoc:doc-property>
                <inxdoc:doc-property name="encoding">utf-8</inxdoc:doc-property>
                <inxdoc:doc-property name="content-format">text</inxdoc:doc-property>
            </inxdoc:doc-properties>
    After repeated failed attempts at the XPath expression to get hold of the "inxdoc:doc-property" values, I used OxygenXML to generate the following XPathExpression:

    Code:
    /inxdoc:inx-document/inxdoc:metadata/inxdoc:doc-properties/inxdoc:doc-property
    This line of code in my app throws an exception though:

    Code:
    XPathExpression myExpression = XPathExpressionFactory.createXPathExpression("/inxdoc:inx-document/inxdoc:metadata/inxdoc:doc-properties/inxdoc:doc-property");
    And the exception is:

    Code:
    com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: inxdoc
    The namespace declaration for inxdoc looks fine to me. Any advice would be greatfully accepted - I am really stuck...

  • #2
    Edit - sorry, this is nothing to do with NodeMapper, it's more to do with XPathExpressionFactory I think....

    I still need help though please

    Comment


    • #3
      I guess your XPathExpression doesn't know about the namespace. Use XPathExpression.createXPathExpression(String expression, Map namespaces). The namespace map should consist of string prefixes mapped to string namespaces.

      Cheers, Dan

      Comment


      • #4
        Thanks Dan, will try that as soon as I get home and post my findings. I did try a dummy file with a basic namespace and it worked (xmlns:test1="blah"), so it's strange that for this real file, it doesn't work. But, explicitly passing in the namespaces sounds like a good idea - I'll give it a shot

        Cheers

        Comment


        • #5
          Worked perfectly, thanks

          Comment

          Working...
          X