XPath and namespaces

I am currently using:
http://www.ibm.com/developerworks/library/x-javaxpathapi.html
to figure out how to extract nodes from an xml with default namespace.
I have this xml:
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.21" id="1">
    <property name="createdBy">Eclipse BIRT Designer Version 2.5.2.v20100208 Build <2.5.2.v20100210-0630></property>
    <property name="units">in</property>
    <page-setup>
        <simple-master-page name="Simple MasterPage" id="2">
                              <xml-property name="waht"> <![CDATA[I DON*T WANT THIS - MASTER]]></xml-property>
        </simple-master-page>
    </page-setup>          
    <body>
        <extended-item name="Book" id="7">
            <xml-property name="xmlRepresentation"><![CDATA[I DON*T WANT THIS - BOOK]]></xml-property>
            <property name="outputFormat">SVG</property>
        </extended-item>          
        <extended-item name="Chart" id="7">
            <xml-property name="xmlRepresentation"><![CDATA[I WANT THIS]]></xml-property>
            <property name="outputFormat">SVG</property>
        </extended-item>
    </body>
</report>I am trying to extract the CDATA test for the element in Body where name = "Chart". Before evaluating the XPath expression I enable the following namespace context:
    xPath.setNamespaceContext(new NamespaceContext() {
      @Override
      public Iterator getPrefixes(String namespaceURI) {
        throw new UnsupportedOperationException();
      @Override
      public String getPrefix(String namespaceURI) {
        throw new UnsupportedOperationException();
      @Override
      public String getNamespaceURI() {
        if (prefix == null) throw new NullPointerException("Null prefix");
        else if ("property".equals(prefix)) return "http://www.eclipse.org/birt/2005/design";
        else if ("xml".equals(prefix)) return XMLConstants.XML_NS_URI;
        return XMLConstants.NULL_NS_URI;
    });When I evaluate using
    try {
      xPathExpression = xPath.compile(text);
    } catch (XPathExpressionException e) {
      e.printStackTrace();
    }where :
text = "//property:xml-property";I get:
I DON*T WANT THIS - MASTER
But I need the CDATA for the Chart (I WANT THIS - CHART). I have then tried this expression:
text = "//property:xml-property[property:name=\"Chart\"]";But it just gives an empty result. Any ideas on how to write the correct xpath expression for this?

This is returning the right data:
tesxt = "//property:extended-item[@name=\"Chart\"]/property:xml-property";

Similar Messages

  • XPath and Namespace

    Hi,
    I'm trying to get a node value of a xml document using org.apache.xpath.XPathAPI class, but I'm doing something wrong, since I'm getting 'null' instead of the node value.
    <?xml version="1.0" encoding="UTF-8"?>
    <pdf xmlns="http://hipoteca.sf/pdf/solicitud">
    <Client>
    <numClient>18150</numClient>
    </Client>
    </pdf>
    I'm doing like this:
    Node node = null;
    String xpath = "/pdf/Client/numClient/text()";
    node = XPathAPI.selectSingleNode(doc.getDocumentElement(),xpath);
    If I eliminate the namespace of the xml document, there is no problem, everthing works fine. But if the root node ('pdf') has a namespace, it doesn't work. I've seen that exists another XPathAPI method called selectSingleNode with an extra parameter, the namespace node, but I don't know how to obtain this namespace node.
    public static Node selectSingleNode(Node contextNode, String str, Node namespaceNode) throws TransformerException
    Please, help me !!! Thanks in advance

    XPath 1.0 and the default namespace do not work together. For examples of why not and what you might do instead see (for example) these:
    http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/1753
    http://www.topxml.com/people/bosley/defaultns.asp

  • Xpath and Namespaces problems

    Hello there! I'm using XPath to parse a document, and so far It was working great! I'm having issues with namespaces though. When the DocumentBuilder is not namespace aware. It works ok. But, when it is namespaceaware. I need to prefix my xpath expressions. for instance "//foo:message". Altough I'm using a namespacecontext and passing it to the Xpath:
    public class FooNamespaceContext implements NamespaceContext {
         public String getNamespaceURI(String prefix) {
              if (prefix == null) throw new NullPointerException("Null prefix");
              else if ("foo".equals(prefix)) return "http://acme.com/foo/schemas";
              else if ("xml".equals(prefix)) return XMLConstants.XML_NS_URI;
              return null;
         public String getPrefix(String arg0) {
              return "foo";
         public Iterator getPrefixes(String arg0) {
              throw new UnsupportedOperationException("Opera��o desnecess�ria para XPath");
    }How can I just use "//message" with no xmlns prefix? Also, if the user changes de prefix on its xml It does not work.
    Could someone point me to a good tutorial or something (the ones I found at Xerces page are not working)
    Regards

    Thanks for your help
    "/ns1:NotificationConfig/ns1:Transport[ns1:TransportName='" + transportName + "'][1]/ns1:TransportClass/text()" Works fine if I add the prefix to the XML document I'm parsing. However I'll need to look into the the namespace binding you suggested for when I cannot guarantee that the prefix will be present.

  • XPath and Namespaces (continued)

    I'm having a problem locating elements, using selectSingleNode() method, in an XML
    file that contains namespaces :=
    <foo xmlns="urn:bar">
    <name>alan</name>
    </foo>
    I've tried to resolve the problem by using a prefix and implementing the
    oracle.xml.parser.v2.NSResolver interface :=
    public java.lang.String resolveNamespacePrefix(java.lang.String prefix) {
    return "urn:bar";
    This sort of works in that I'm now able to locate the root element foo by
    using :=
    doc.selectSingleNode(doc, "/xxx:foo");
    However searching for a child of the root returns null
    doc.selectSingleNode(doc, "/xxx:foo/name");
    Any Ideas ?
    null

    Use:
    doc.selectSingleNode(doc, "/xxx:foo/xxx:name");

  • Xpath and namespace tag problem...

    hello,
    I have added targetNamespaces to a schema from which i am producing objects via JAXB. it has resulted in a problem!
    Orignal xml document entry produced by JAXB:
    <job>
    <operationName>Operation Test</operationName>
    </job>
    New xml document entry produced by JAXB :
    <job>
    <operationName xmlns="http://www.me.co.uk/me/bus"> Operation Test</operationName>
    </job>
    Xpath query:
    "/job/operationName"
    returned a value ("Operation Test"), now with the namespace modifications it returns "" Any ideas?
    I tried
    /job/operationName/[@*] but still got nothing back
    cheers
    m

    It is possible to use xpath when working with default namespaces. I do not use jaxB, but with jaxP en the methods described in: http://java.sun.com/developer/technicalArticles/xml/validationxpath/
    it all works.
    Example:
    java-code
    import org.w3c.dom.*;
    import javax.xml.xpath.*;
    import org.xml.sax.SAXException;
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = builder.parse(new File("users.xml"));
        String expression = "/users/user[@id='0']";
        XPath xpath = XPathFactory.newInstance().newXPath();
        Node userNode = (Node) xpath.evaluate(expression, doc, XPathConstants.NODE);
    } catch (SAXException se) {
        se.printStackTrace();
    } catch (XPathExpressionException xe){
        xe.printStackTrace();
    user.xml
    <users
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns="http://www.sphemy.com/xmlrss/user"
              xsi:schemaLocation="http://www.sphemy.com/xmlrss/user user.xsd">
         <user id="0">
              <loginName>guest</loginName>
              <password>guest</password>
         </user>
    </users>
    user.xsd
    <xs:schema
              xmlns:xs="http://www.w3.org/2001/XMLSchema"
              xmlns="http://www.sphemy.com/xmlrss/user"
              targetNamespace="http://www.sphemy.com/xmlrss/user"
              elementFormDefault="qualified">
         <xs:element name="users">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="user" type="UserType" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:complexType name="UserType">
              <xs:sequence>
                   <xs:element name="loginName" type="xs:string"/>
                   <xs:element name="password" type="xs:string"/>
              </xs:sequence>
         </xs:complexType>
    </xs:schema>Edited by: sphemy on Jan 2, 2009 4:50 AM

  • Is there any  example snippet for XPath using namespace

    Hi,
    I have used XpathApi class to get the XML node matching my xpath that does not deal with namespaces and it works for me. However, it does not seem to work well when I construct the xpath with namespaces (probably I may be doing something wrong example: //ns:node1/@ns:attr1).
    Can anyone give pointers or some example snippet or some links to handle Xpath with namespaces.
    Also if there is any better approach (Classes or framework) for handing XPath with namespaces then please let me know.
    Thanks,
    -vc

    AnkitG wrote:
    Hi All,
    Is there any example for N9010A EXA signal analyzer , I tried to use example of MXA got from the driver page but couldnt get to work. I need to capture the RF data form the analyzer. Please let me know if there any example or way to do it.
    That is an Agilent instrument. Shouldn't be looking for examples on THEIR website?????

  • Xpath and Get XML Document Data

    Good Morning,
    I have just recently gotten involved in a project that requires communicating with some web services (axis2). We have existing scripts that handle this already, but they were built when we weren't on axis2 so now the XML output from the web service call is slightly different and i am no longer able to use the same xpath statement in the Get XML Document Data step.
    I am receiving either null values or a prefix namespace error. I am new to xpath and have been reading as best i can from http://www.w3schools.com/xpath/ to try and understand how to write my statements to pull out the data i want correctly.
    I have read that sometimes the editor has problems if the XML contains namespace declarations, etc.
    Below is an example XML output where I'd like to be able to read the value in the ax211:success. My xpath gets prefix namespace errors as it doesn't recognize ax211.
    Xpath: /descendant::ns:validateCertificationResponse/child::ns:return/child::ax211:success
    Perhaps my xpath statement is just incorrect and wouldn't retrieve what i expect it to....
    Any advice is appreciated.
    Thanks,
    Kevin

    Hi,
    well, it appears that text() is automatically appended to the XPath query for some reason in UCCX, this is why you actually see the text node within the ax211:success element. This //*[local-name()="success"] select the whole node, not its first child (which is actually the first element, which also happens to be a text).
    Anyway,
    // - anywhere
    * - any node
    And within this "everything" you actually search with the condition within the angular brackets.
    G.

  • Xpath and context objects

    hi expects,
        what is difference between xpath and context objects?

    Rohit,
    Check this thread for bhavesh reply for this:
    Context object
    ---Satish

  • Soap sender adpater issue missing sender interface and namespace in the msg

    Hi Expert,
    I got a problem when try to using soap sender adapter.
    Here is the sceanrio:
    Http web service client call ---PI soap sender adapter -some routing data-business system inbound.
    Sytem information:
    SAP_ABA     700     0019     SAPKA70019     Cross-Application Component
    SAP_BASIS     700     0019     SAPKB70019     SAP Basis Component
    PI_BASIS     2005_1_700     0019     SAPKIPYJ7J     PI_BASIS 2005_1_700
    ST-PI     2008_1_700     0001     SAPKITLRD1     SAP Solution Tools Plug-In
    SAP_BW     700     0021     SAPKW70021     SAP NetWeaver BI 7.0
    ST-A/PI     01L_BCO700     0000          -     Servicetools for other App./Netweaver 04
    Here is my problem. I use soapui trigger a test msg to PI system. But in the sxmb_moni, only sender service is there.
    The sender interface and sender namespace is missing. And the msg has error called: :INTERFACE_REGISTRATION_ERROR.
    Which means I do not have a inbound interface to process the msg.
    But I suppose to redirect the msg to business system.
    Here is the configuration:
    reciever determination: soap sender service, soap outbound interface, soap interface namespace --> reciever business sytem.
    Interface ditermination: soap sender service, soap interface --> receiver interface, receiver namespace.
    Sender agreement: soap service, soap itnerface --- soap communication channel
    receiver agreement, soap service---> receiver sevice, receiver interface, reciever namespace  and reciever cummunication channel
    define of soap sender adapter:
    soap sernder, with use encoded header and use query string checked and qos as exactly once.
    Anyone has any idea here? Many thanks! And most strange thing is yesterday it works and today it failed.
    Please kindly help here.
    Thanks a lot,
    Leon

    Hi guys,
    thanks for the input.
    Hi Sven,
    I have input default interface and namespace.
    Hi sivasakthi,
    Regarding mistype, it may happen, I will do it again right away.
    And the URL is generated by the wsdl toolkit in the directory.
    I marked use encoded header and query string in the communication channel.
    I will generate the wsdl again and test it again.
    Regarding URL(endpoint of web service):
    http://hostname:50000/XISOAPAdapter/MessageServlet?channel=:AGSSAL_SOAP:AGSSAL_SOAP_CC&version=3.0&Sender.Service=AGSSAL_SOAP&Interface=urn:a1s_saplivelinkcontent.service.sap.com^MI_O_AS_DELIVERNOTIFY_SOAP
    Again thanks for you guys help.
    Best regards,
    Leon

  • Deleting Message Type name and namespace tag from XML payload

    Hi Gurus,
    Need help. My payload looks like this
    <?xml version="1.0" encoding="utf-8" ?>
    - <ns1:MT_O_sss xmlns:ns1="http://sap.com/xi/tm">
    - <Job>
       <Field name="xxxx" value="" />
      <Field name="xxx" value="" />
      <Field name="xxx" value="" />
       </Job>
      </ns1:MT_O_sss>
    But The soap webservice is expecting it in
    <?xml version="1.0" encoding="utf-8" ?>
    - <Job>
       <Field name="xxxx" value="" />
      <Field name="xxx" value="" />
      <Field name="xxx" value="" />
       </Job>
    I have to remove the message type name and namespace tag.
    So how can I achieve this. I am sending this payload using a Receiver Soap Adapter. Please help. I am kind of stuck.

    hi,
    you have to simply add one module in your communication channel
    that is XMLAnonymizerBean
    you can refer below for help:
    Remove namespace prefix or change XML encoding with the XMLAnonymizerBean
    http://help.sap.com/saphelp_nw04/helpdata/en/2e/bf37423cf7ab04e10000000a1550b0/frameset.htm
    hope it helps.
    regards,
    ujjwal kumar

  • Need information about interfaces and namespaces in actionscript 3.0

    Hi,
    I need information about actionscript interfaces and
    namespaces, I'm preparing for ACE for Flash CS3 and I need to learn
    about this subjects and I can not find resources or simple examples
    that make these subjects understandable.
    Anybody can help me!
    Thanks a lot.

    Interfaces (cont.)
    Perhaps the most useful feature of interfaces is that you not
    only can define the data type but also method signature of the
    class that implements this interface. In other words, interface can
    define and enforce what methods class MUST implement. This is very
    useful when classes are branching in packages and team of
    developers works on a large application among others.
    The general syntax for an Interface with method signatures is
    written the following way:
    package{
    public interface InterfaceName {
    // here we specify the methods that will heave to be
    implemented
    function method1 (var1:dataType,
    var2:datType,…):returnType;
    function method2 (var1:dataType,
    var2:datType,…):returnType;
    To the previous example:
    package{
    public interface IQualified {
    function method1 ():void;
    function method2 ():int;
    Let’s write a class that implements it.
    If I just write:
    package{
    public class ClassOne extends DisplayObject implements
    IQualified {
    public function ClassOne(){}
    I will get a compilation error that states that I did not
    implement required by the interface methods.
    Now let’s implement only one method:
    package{
    public class ClassOne extends DisplayObject implements
    IQualified {
    private function method1():void{
    return;
    public function ClassOne(){}
    I will get the error again because I implemented only one out
    of two required methods.
    Now let’s implement all of them:
    package{
    public class ClassOne extends DisplayObject implements
    IQualified {
    private function method1():void{
    return;
    private function method2():int{
    return 4;
    public function ClassOne(){}
    Now everything works OK.
    Now let’s screw with return datatypes. I attempt to
    return String instead of void in method1 in ClassOne:
    private function method1():String{
    return “blah”;
    I am getting an error again – Interface requires that
    the method1 returns void.
    Now let’s attempt to pass something into the method1:
    private function method1(obj:MovieClip):void{
    return;
    Oops! An error again. Interface specified that the function
    doesn’t accept any parameters.
    Now rewrite the interface:
    package{
    public interface IQualified {
    function method1 (obj:MovieClip):void;
    function method2 ():int;
    Now compiler stops complaining.
    But, if we revert the class back to:
    private function method1():void{
    return;
    compiler starts complaining again because we don’t pass
    any parameters into the function.
    The point is that interface is sort of a set of rules. In a
    simple language, if it is stated:
    public class ClassOne implements IQualified
    it says: “I, class ClassOne, pledge to abide by all the
    rules that IQualified has established and I will not function
    correctly if I fail to do so in any way. (IMPORTANT) I can do more,
    of course, but NOT LESS.”
    Of course the class that implements an interface can have
    more that number of methods the corresponding interface requires
    – but never less.
    MORE means that in addition to any number of functions it can
    implement as many interfaces as it is desired.
    For instance, I have three interfaces:
    package{
    public interface InterfaceOne {
    function method1 ():void;
    function method2 ():int;
    package{
    public interface InterfaceTwo {
    function method3 ():void;
    package{
    public interface InterfaceThree{
    function method4 ():void;
    If our class promises to implement all three interface it
    must have all four classes in it’s signature:
    package{
    public class ClassOne extends DisplayObject implements
    InterfaceOne, InterfaceTwi, InterfaceThree{
    private function method1():void{return;}
    private function method2():int{return 4;}
    private function method3():void{return;}
    private function method4():void{return;}
    public function ClassOne(){}
    Hope it helps.

  • Private dictionaries and Namespaces

    Private dictionaries and Namespaces
    We ran into an issue with some email templates in converting from RC2006 to RC2008.3 where Namespace values from Private service dictionaries were not populating correctly in RC2008.
    In the upgrade process from RC2006, any private dictionaries are converted to actual dictionaries. They are created in the Dictionary Group UPGD: PRIVATE DICTIONARIES and the dictionary name is based on the service name: PRIV_ServiceA.
    What I found as we were testing is that the Namespace parameters in Email templates (and, presumably, conditional statements and other places) no longer worked.
    The reason is that the Namespace Parameter for a private dictionary did not use a dictionary name, e.g. #SERVICE.DATA.Field1#. In order for the RC2008 version to work, we had to add dictionary references:  #SERVICE.DATA.PRIV_ServiceA.Field1#.

    Hey M.VAL,
    Thanks for the question. If your dictionary is not available after updating your device, you may need to redownload it:
    iOS: Dictionary isn't available after updating to the latest version of iOS
    http://support.apple.com/kb/TS5238
    Thanks,
    Matt M.

  • XPATH and the C parser

    Can I use an 'XPATH' expression to find a node using the C parser?
    eg find '/A/B/C'
    The Oracle Java parser supports this.
    Thanks for your help.
    Doug

    Yes, we have Xpath and XSLT support in the parser.

  • XPath and ERMS

    Hi gurus,
    We're creating our own Services for ERMS (CRM 6.0) and I was after a spot of advice.
    Can anyone give me some guidance as to where to find all the XPATH entries available? 
    In the ERMS Repository there are attributes defined with XPATH entries against them, but I'm sure there must be other XPATH entries available, and if we wanted to define our own attributes I was wondering where I could look to find this XPATH information?
    Thanks in advance,
    Andrew G.

    Hi !
    WSDL, XSD, Xpath and BPEL are all open standard.
    ABAP for instance, is not an open standard.
    look at the below URL's for more details
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/cfab6fdd-0501-0010-bc82-f5c2414080ed
    BPEL in a Nutshell
    WS-BPEL 2.0 from OASIS - How it has progressed since BPEL 1.1
    BPEL Glossary for Developers
    Regards
    Abhishek

  • XPath and oracle parser

    Hi,
    I am using Oracle parser to parse my XML file, as i found that it is faster then IBM and sun parser, But i think it does not support XPath, so how can i use XPath and oracle parser, I can also use Sun parser , but dont know if it has XPath support,
    So please help me out

    I suppose it supports DOM or a saxHandler that can provides you a DOM
    tree. For Xpath, may I suggest you my solution : http://www.japisoft.com/jxpath
    Regards,
    A.brillant

Maybe you are looking for

  • Performance on intel imac - system almost unusable

    I'm running iPhoto 6.04 on a 2GHz intel imac with 2GB of Ram. When I launch iPhoto -- everything slows unbearably. Even the typing speed in other applications, the finder is unresponsive, applications quit, It takes forever to switch between applicat

  • Time out error in webdynpro

    Hi all, We are facing a time out error uisng webdynpro. The webdynpro application is mapped to the enterprise portal for the users. When ever the users loads the application and first click on the link then again loads the application and click any l

  • Detecting cursor change

    Hello, does anybody know how I can detect a cursor change in a XY graph? Lars

  • NameNotFoundException while reconciling OIM  from ldap

    Hi experts, please help me to resolve this OIM sync issue. When I ran LDAPConfigPostSetup.sh to reconcile OIM from OID all most all ldap entries are entered into OIM except few which are under cn=OracleContext. I am getting around 20 below messages :

  • Trying to download Indesign cs6 trial

    The download assistant say tha the file size is 879mb, but so far the file that has been down loaded is over 1.5g and does not show any signs of installing. Any ideas?