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

Similar Messages

  • 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

  • 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 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

  • Dom Parsing and BR tag problem...

    hi all,
    I have a Dom parser which examines an xml file and creates a Jtree from its content... it works fine except that when it meets a </br> tag it creates a new node for it in the tree... is there anyway to get it to consider the two "node" as one...
    example:
    - <p>
    some text 1
    some text 2
    </p>
    should be added in one node as some text 1 some text 2 instead it puts some text 1 in one node and some text 2 in another....
    thanks
    Lila

    oooh sorry i didnt check how the message looked this is the question:
    hi all, I have a Dom parser which examines an xml file and creates a Jtree from its content... it works fine except that when it meets a / BR tag it creates a new node for it in the tree... is there anyway to get it to consider the two "node" as one... example: -
    < p >
    some text 1
    < / BR > <--- THIS NODE IS PROBLEM
    some text 2
    < / p >
    should be added in one node as some text 1 some text 2 instead it puts some text 1 in one node and some text 2 in another....
    thanks
    Lila

  • 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");

  • Lumia 630 and treasure tag problem

    Hello,
    I justa purchased a tresure tag WS-2 and connected it to my Nokia Lumia 630.
    Bluetooth on my phone is on. I can setup the tag (i.e. name it).
    Software seams not to work properly.
    When i get away from the tag, the tag makes the sound, but my phone doesnt make any sound nor any written notification. Also there is no option to locate the tag in the Here map.
    Any suggestions or similar problems?
    Thanks in advance
    Solved!
    Go to Solution.

    Did whatever you suggested but yet nothing.
    Option show in map does not appear at all.
    All notifications are set "on"
    Do you think my location may be an issue?
    I am in Greece and the phone is set in greek.
    Edit: Demonstration works fine. Both tag and phone make the noise
    Attachments:
    Φωτογραφία0328(2).jpg ‏259 KB

  • Tag insight and closing tags problem

    I am a touch-typist, and as such, CF-Builder has a very irritating problem. Let me explain:
    One of the nice things about CFEclipse is that it senses when you have entered a closing element (i.e., #, }, ], ", etc.) When this occurs, it automatically moves the cursor forward WITHOUT leaving a duplicate. The fact that builder does NOT do this is very frustrating. It requires you to remove hands from the keyboard to hit the right-arrow, or you have to turn off the closing tags in the preferences.
    Other than that, seems like a pretty decent editor.

    I couldn't agree more. It's the little things that matter...

  • 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";

  • Where can I get an Html error report of all the syntax and tag problems?

    Where can I get an Html error report of all the syntax and tag problems?

    Thank you for your answer.
    Where is the DW validation for me?
    My files are in my computer so I don’t have an external URL.
    File > validation > as xml = closes DW... Maybe because it is not a correct command for HTML,
    And
    Window > results > validation = gives a partial mistakes (e.g. shows an open tag without closing tag, but doesn’t show a closing tag without an open tag).
    Thank you.

  • No Namespace tag in XML file

    Hi
    I wish to read an XML file coming from another system and then update my data base using RFC.
    The problem is that the incoming file does not contain a namespace tag which XI understands
    (For e.g. <ns:UpdateTablexmlns:ns="urn:BuisScenario:TEST">)
    Due to which it is not reading the data contained in the file.
    If I use the XML file which is generated through XI then it is working fine as it contains the relevant namespace.
    But as my XML file is coming from a different system and is not generated by XI, I wish to know how can we add the namespace tag to it so that XI can understand the file. Or is there any other way in which the file can be read.
    Has anybody face similar problem?
    Hoping for a quick response.
    Regards
    Satish

    Hi Stephan
    The problem of namespace is solved now, what I did was, I followed your suggestion and I have left the field for XML Namespace in the message type empty and the scenario works. Now I am facing another problem.
    My incoming XML file looks like as given below:
        <Case_Details>
         <Case1>                          <Case_EPC>1232312313313</Case_EPC>               <Item_ID>PR001</Item_ID>                    <Quantity>50</Quantity>                    </Case1>
         <Case2>                         <Case_EPC>1232312313314</Case_EPC>               <Item_ID>PR002</Item_ID>                    <Quantity>200</Quantity>                    </Case2>
         <Case3>                         <Case_EPC>1232312313315</Case_EPC>               <Item_ID>PR003</Item_ID>                    <Quantity>520</Quantity>
         </Case3>
       </Case_Details>
    The problem is when I duplicate the cases while testing the message mapping I do not get the desired result as the tag names are different. The mapping which I have done does not cater for Case1, Case2, Case3 coming in the incoming XML file, Instead of this only case tag comes without the numbering(1,2,3) due to which my fields are not getting populated.
    The sample XML generated from my mapping is given below.
      <Case_Details>
            <Case>                          <Case_EPC>1232312313313</Case_EPC>               <Item_ID>PR001</Item_ID>                    <Quantity>50</Quantity>                    </Case>
         <Case>                         <Case_EPC>1232312313314</Case_EPC>               <Item_ID>PR002</Item_ID>                    <Quantity>200</Quantity>                    </Case>
         <Case>                         <Case_EPC>1232312313315</Case_EPC>               <Item_ID>PR003</Item_ID>                    <Quantity>520</Quantity>
         </Case>
        </Case_Details>
    So in this scenario the different cases do not have numbering and thus the mapping fails when the original XML file is the input.
    Kindly advice what is to be done.
    Regards
    Satish

  • Keep namespace tags throughout the message mapping in XI

    Hi!
    I am facing the following problem:
    A backend application sends out XML messages that all have a namespace tag in the element names:
    <ns1:StandardBusinessDocument xmlns:ns1="http://www.unece.org/cefact/namespaces/SBDH" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:eanucc="urn:ean.ucc:2" xmlns:deliver="urn:ean.ucc:deliver:2" xsi:schemaLocation="http://www.unece.org/cefact/namespaces/SBDH ../Schemas/sbdh/StandardBusinessDocumentHeader.xsd urn:ean.ucc:2 ../Schemas/ReceivingAdviceProxy.xsd">
    <ns1:StandardBusinessDocumentHeader>
    <ns1:HeaderVersion>2.2</ns1:HeaderVersion>
    <ns1:Sender>
    <ns1:Identifier Authority="EAN.UCC">1234567890123</ns1:Identifier>
    </ns1:Sender>
    Problem is that the backend expects the reply from XI to look the same (ns0: or ns1: in front of every element name). But when I import the xsd into XI, it removes these tags and the message then looks completely different to the backend:
    <ns0:StandardBusinessDocument xmlns:ns0="urn:ean.ucc:2" ns1="http://www.unece.org/cefact/namespaces/SBDH" eanucc="urn:ean.ucc:2" deliver="urn:ean.ucc:deliver:2" schemaLocation="http://www.unece.org/cefact/namespaces/SBDH ../Schemas/sbdh/StandardBusinessDocumentHeader.xsd urn:ean.ucc:2 ../Schemas/ReceivingAdviceProxy.xsd" xsi="http://www.w3.org/2001/XMLSchema-instance"><StandardBusinessDocumentHeader><HeaderVersion>2.2</HeaderVersion><Sender><Identifier Authority="EAN.UCC">1234567890123</Identifier></Sender>
    Any help on how to make XI keep the namespace tags is greatly appreciated!
    Cheers!
    Stefan

    Hi Stefan,
    plz have a look to following german sides:
    Stefan Münz: XSLT
    Informationen zur Extensible Markup Language
    Einführung in XSL-Transformation (XSLT)
    You have to do a construction like
    <ns1:Sender>
    <ns1:Identifier Authority="EAN.UCC">
    <xsl:value-of select="//X-Path expression on my source field"></xsl:value-of></ns1:Identifier>
    </ns1:Sender>
    Regards,
    Udo

  • 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.

  • Itunes Library and ID3 tags

    Hi,
    So here's my problem :
    I spent hours cleaning my MP3 collection and re-Writing ID3 tags in order to have a clean Itunes Library without "Blink 182" and "Blink-182" (for exemple) in the Explorer but just "Blink 182".
    And importing my tied up music in the library, I noticed that there still was "Blink-182".
    I checked my ID3v1 and ID3v2 tags : They're all the same : "Blink 182".
    I don't understand where iTunes takes these artists name since they aren't in the tags.
    Can you help me or these hours of cleaning where worthless ?
    Thanks

    If you open iTUnes, rightclick the song, hit "Get Info" and the artist field is "Blink 182" instead of "Blink-182" then all you need to do is play the song and iTunes should read the tag and correct the info.
    If it does not do this one of the 2 is most likly happening, theres multiple tags on the song that needs to be stripped off using the program "TidyMP3" or windows media player is "Sneaking around" in the background and changing them back based on the info its getting off the net, in which case you will have to open WMP, goto tools>oPtions>Library tab and UNCHECK "Retrieve info off the internet"

  • b and i tags not working in StyleableTextField for mobile development

    I'm trying to dynamically produce TextArea instances in a Flex mobile app that implement html formatting.  I've made a lot of progress, but simple <b> and <i> tags are not being rendered correctly. 
    My current hypothesis is that I need to embed the italic and bold fonts.  I am currently not embedding fonts for these particular TextArea instances at all -- they are rendering using the system font.  In my previous experience, this eliminates problems with rendering <b> and <i> text.  However, when deploying on mobile platforms, I don't know for sure if there is a bold or italic system font natively available. 
    If I need to embed the bold and italic fonts for the tags to process correctly, does anyone know which font(s) I should embed and how I should name them so that the html will be able to find them and render correctly?  I am applying a CSS to these TextArea instances in the full app, so I can do any font embedding there if necessary.  I am planning to compile this app for both iOS and Android, in case that makes a difference. 
    Below is a simplified example of the code I'm using.  The TextArea that is generated is formatted honoring the <br /> tags, but ignoring the <b> and <i> tags. 
    Thanks in advance for any help. 
    import mx.events.FlexEvent;
    import spark.components.TextArea;
    import spark.components.supportClasses.StyleableTextField;
    import spark.skins.mobile.TextAreaSkin;
    protected function application1_creationCompleteHandler(event:FlexEvent):void
              var textArea0:TextArea = new TextArea();
              textArea0.setStyle("skinClass", TextAreaSkin);
              addElement(textArea0);
              var styleableTextField0:StyleableTextField = StyleableTextField(textArea0.textDisplay);
              styleableTextField0.multiline = true;
              styleableTextField0.htmlText = "<b>bold</b><br /><i>italic</i><br />normal";

    Huh!  I tried tracing the htmlText property after formatting, and the bold and italic tags are not there anymore.  Unexpected, but consistent with the results.  Thanks for suggesting that test.  Here is the line where I assign the htmlText property:
    styleableTextField0.htmlText = "normal<br/><i>italic</i><br/><b>bold</b><br/><a href='http://www.google.com/'>link</a>";
    Here is the section where I create the StyleSheet and assign it to the StyleableTextField:
    var styles:String =
      "@font-face{ fontFamily: Arial; src: url('assets/fonts/Arial.ttf'); embedAsCFF: false;}" +
      "@font-face{ fontFamily: Arial; src: url('assets/fonts/Arial Italic.ttf'); fontStyle: italic; embedAsCFF: false;}" +
      "@font-face{ fontFamily: Arial; src: url('assets/fonts/Arial Bold.ttf'); fontWeight: bold; embedAsCFF: false;}" +
      "a { color: #FFE043; textDecoration: underline; } " +
      "a:active{ color: #ffffff;}" +
      "b{fontWeight:bold; fontFamily: Arial;} " +
      "i{fontStyle:italic; fontFamily: Arial;}";
    var myStyleSheet:StyleSheet = new StyleSheet();
    myStyleSheet.parseCSS(styles);
    styleableTextField0.styleSheet = myStyleSheet;
    And here is the trace statement
    trace( styleableTextField0.htmlText); // <TEXTFORMAT RIGHTMARGIN="21" INDENT="10" LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="16" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">normal</FONT></P></TEXTFORMAT><TEXTFORMAT RIGHTMARGIN="21" INDENT="10" LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="16" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">italic</FONT></P></TEXTFORMAT><TEXTFORMAT RIGHTMARGIN="21" INDENT="10" LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="16" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">bold</FONT></P></TEXTFORMAT><TEXTFORMAT RIGHTMARGIN="21" INDENT="10" LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="16" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0"><A HREF="http://www.google.com/" TARGET="">link</A></FONT></P></TEXTFORMAT>
    Lots of code modification going on behind the scenes, it would seem.  Any idea as to why the bold and italic tags are being stripped out when the formatting process happens?  Any idea of what steps I could take next?  Thanks for all your help so far! 
    BTW, here's a screen capture of what the text looks like at this point:

Maybe you are looking for