libxml-ruby namespace problem

Discussion in 'Ruby' started by mortee, Oct 26, 2007.

  1. mortee

    mortee Guest

    I'm trying to use libxml-ruby 0.5.2.0 on cygwin. The XML I want to parse
    has a namespace declaration on the root node, but this namespace isn't
    given a prefix.

    My problem is that when I try to match elements using e.g.
    XML::Document#find, it won't match any.

    If I specified a prefix for the document's NS in the XML file, and used
    element names qualified by that prefix in the xpath expression, it finds
    what I'm looking for. Also, if I remove the NS declaration from the root
    node, then it finds elements with unspecified names in the xpath expression.

    Too bad I can't tweak the XML input I'd have to handle like I can with
    test files.

    So my question is, how can I have libxml-ruby to ignore the namespace on
    the document and find elements using unqualified names; or how can I
    specify what namespace it should assume for the unqualified names in the
    xpath?

    The docs mention a namespace parameter to the #find method, but I was
    unable to figure out how I'm supposed to specify the NS there.

    thx
    mortee
     
    mortee, Oct 26, 2007
    #1
    1. Advertising

  2. mortee

    mortee Guest

    Follow-up to myself:

    Actually, libxml-ruby won't find what I'm looking for if either a
    namespace or a DOCTYPE declaration is present in the document. I had to
    remove both to get results.

    If I have only the DOCTYPE in the document, it doesn't raise an
    exception for e.g. the document not conforming to the specified DTD, it
    just returns empty result sets.

    mortee wrote:
    > I'm trying to use libxml-ruby 0.5.2.0 on cygwin. The XML I want to parse
    > has a namespace declaration on the root node, but this namespace isn't
    > given a prefix.
    >
    > My problem is that when I try to match elements using e.g.
    > XML::Document#find, it won't match any.
    >
    > If I specified a prefix for the document's NS in the XML file, and used
    > element names qualified by that prefix in the xpath expression, it finds
    > what I'm looking for. Also, if I remove the NS declaration from the root
    > node, then it finds elements with unspecified names in the xpath expression.
    >
    > Too bad I can't tweak the XML input I'd have to handle like I can with
    > test files.
    >
    > So my question is, how can I have libxml-ruby to ignore the namespace on
    > the document and find elements using unqualified names; or how can I
    > specify what namespace it should assume for the unqualified names in the
    > xpath?
    >
    > The docs mention a namespace parameter to the #find method, but I was
    > unable to figure out how I'm supposed to specify the NS there.
    >
    > thx
    > mortee
    >
    >
    >
     
    mortee, Oct 26, 2007
    #2
    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. Ian Gregory
    Replies:
    1
    Views:
    507
  2. Olav
    Replies:
    3
    Views:
    4,251
  3. Francis Hwang

    Problem installing ruby-libxml

    Francis Hwang, Nov 26, 2003, in forum: Ruby
    Replies:
    1
    Views:
    149
    Sam Roberts
    Dec 4, 2003
  4. Ross Bamford

    [ANN] LibXML-Ruby 0.3.6

    Ross Bamford, Feb 23, 2006, in forum: Ruby
    Replies:
    27
    Views:
    253
    Daniel Harple
    Feb 26, 2006
  5. Dan Stevens (IAmAI)

    Cannot install ruby gem 'libxml-ruby'

    Dan Stevens (IAmAI), Mar 1, 2007, in forum: Ruby
    Replies:
    0
    Views:
    179
    Dan Stevens (IAmAI)
    Mar 1, 2007
Loading...

Share This Page