Reading Xpath element

Discussion in 'XML' started by MarcoT77@gmail.com, May 4, 2005.

  1. Guest

    Hi Teacher.

    I'm trying to get with Xpath the Product nodes in the following XML:
    <?xml version="1.0" encoding="utf-8"?>
    <PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"
    schemaVersion="5.1" date="2005-05-03" time="16:41:33" author="TcEng -
    infodba@bridge(389284449)">
    <Header id="id1" traverseRootRefs="#id2 #id11"
    transferContext="exp_folder"></Header>
    <Product id="id10" name="Ace" accessRefs="#id3" subType="Drawing"
    productId="000002">
    <ApplicationRef version="QRJJ3Vh1xNEIWA" application="TcEng"
    label="QRJJ3Vh1xNEIWA"></ApplicationRef>
    <UserData id="id33">
    <UserValue type="reference" value="" title="owning_user"
    dataRef="#id11"></UserValue>
    <UserValue value="0-01-00T00:00:00" title="date_released"></UserValue>
    <UserValue value="2005-05-03T14:00:32"
    title="last_mod_date"></UserValue>
    <UserValue type="reference" value="" title="last_mod_user"
    dataRef="#id11"></UserValue>
    <UserValue type="reference" value="" title="owning_group"
    dataRef="#id27"></UserValue>
    <UserValue value="2005-05-03T10:46:39"
    title="creation_date"></UserValue></UserData></Product> (Continue...)

    I've used the /PLMXML/Product query but I can't get anything.

    I've also tried this simple xml:
    <?xml version='1.0'?>
    <Books>
    <Book>
    <Title>Beginning XML</Title>
    <Publisher>Wrox</Publisher>
    </Book>
    <Book>
    <Title>XML Step by Step</Title>
    <Publisher>MSPress</Publisher>
    </Book>
    <Book>
    <Title>Professional XML</Title>
    <Publisher>Wrox</Publisher>
    </Book>
    <Book>
    <Title>Developing XML solutions</Title>
    <Publisher>MSPress</Publisher>
    </Book>
    </Books>

    And on this Xml the rule /Books/Book works fine.

    Why does not the first rule work?
    Am I missing something?

    Thanks in advance.
    Marco.
     
    , May 4, 2005
    #1
    1. Advertising

  2. wrote:
    > Hi Teacher.
    >
    > I'm trying to get with Xpath the Product nodes in the following XML:
    > <?xml version="1.0" encoding="utf-8"?>
    > <PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"
    > schemaVersion="5.1" date="2005-05-03" time="16:41:33" author="TcEng -
    > infodba@bridge(389284449)">
    > <Header id="id1" traverseRootRefs="#id2 #id11"
    > transferContext="exp_folder"></Header>
    > <Product id="id10" name="Ace" accessRefs="#id3" subType="Drawing"
    > productId="000002">
    > <ApplicationRef version="QRJJ3Vh1xNEIWA" application="TcEng"
    > label="QRJJ3Vh1xNEIWA"></ApplicationRef>
    > <UserData id="id33">
    > <UserValue type="reference" value="" title="owning_user"
    > dataRef="#id11"></UserValue>
    > <UserValue value="0-01-00T00:00:00" title="date_released"></UserValue>
    > <UserValue value="2005-05-03T14:00:32"
    > title="last_mod_date"></UserValue>
    > <UserValue type="reference" value="" title="last_mod_user"
    > dataRef="#id11"></UserValue>
    > <UserValue type="reference" value="" title="owning_group"
    > dataRef="#id27"></UserValue>
    > <UserValue value="2005-05-03T10:46:39"
    > title="creation_date"></UserValue></UserData></Product> (Continue...)
    >
    > I've used the /PLMXML/Product query but I can't get anything.


    with XPath, unprefixed elements refers to elements that are not bound to
    a namespace URI ; in XML, unprefixed elements may be bound to a
    namespace URI ; this is the case in the document above, and not the case
    in the document below
    thus, /PLMXML gets the PLMXML element with no namespace URI, that
    doesn't appear anywhere ; to get the PLMXML element bound to this
    namespace URI "http://www.plmxml.org/Schemas/PLMXMLSchema", you must
    declare a mapping between a prefix and the namespace URI :
    plm -> "http://www.plmxml.org/Schemas/PLMXMLSchema"
    and then use it in your XPath expression :
    /plm:pLMXML/plm:product
    how to declare the mapping vary according to the XPath engine you use,
    but people usually use it with XSLT ; with XSLT, namespaces declarations
    are used by the XPath engine

    >
    > I've also tried this simple xml:
    > <?xml version='1.0'?>
    > <Books>
    > <Book>
    > <Title>Beginning XML</Title>
    > <Publisher>Wrox</Publisher>
    > </Book>
    > <Book>
    > <Title>XML Step by Step</Title>
    > <Publisher>MSPress</Publisher>
    > </Book>
    > <Book>
    > <Title>Professional XML</Title>
    > <Publisher>Wrox</Publisher>
    > </Book>
    > <Book>
    > <Title>Developing XML solutions</Title>
    > <Publisher>MSPress</Publisher>
    > </Book>
    > </Books>
    >
    > And on this Xml the rule /Books/Book works fine.
    >
    > Why does not the first rule work?
    > Am I missing something?
    >
    > Thanks in advance.
    > Marco.
    >



    --
    Cordialement,

    ///
    (. .)
    -----ooO--(_)--Ooo-----
    | Philippe Poulard |
    -----------------------
     
    Philippe Poulard, May 4, 2005
    #2
    1. Advertising

  3. wrote:


    > I'm trying to get with Xpath the Product nodes in the following XML:
    > <?xml version="1.0" encoding="utf-8"?>
    > <PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"
    > schemaVersion="5.1" date="2005-05-03" time="16:41:33" author="TcEng -
    > infodba@bridge(389284449)">


    > I've used the /PLMXML/Product query but I can't get anything.


    See
    <http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, May 4, 2005
    #3
  4. Marco Guest

    Thanks guys!

    I'm using libxml2 libraries from C, and I solved the problem matching
    nodes with name and namespace-uri attributes because I can't control
    the xml format.
     
    Marco, May 4, 2005
    #4
  5. This is a FAQ (you may want to see the xsl-list faq at
    www.dpawson.co.uk)


    <PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"

    That is an element with local name PLMXML and namespace http://www.plmxml.org/Schemas/PLMXMLSchema

    I've used the /PLMXML/Product

    That matches elements PLMXML and Product in no-namespace.

    Add

    xmlns:p="http://www.plmxml.org/Schemas/PLMXMLSchema"

    to your xsl:stylesheet element and then use

    /p:pLMXML/p:product

    To match elements in this namespace.

    David
     
    David Carlisle, May 9, 2005
    #5
    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. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    2,031
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,533
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    573
  4. Ian Wilson
    Replies:
    2
    Views:
    572
    Ian Wilson
    Jul 26, 2007
  5. HANM
    Replies:
    2
    Views:
    767
    Joseph Kesselman
    Jan 29, 2008
Loading...

Share This Page