I changed my code to use the NamespaceContext, unfortunately I am still not
getting any matches (tried some simpler strings to test as well).  Also, it
seems that adding this bit of code really slowed down the processor, though
it may just be how many times I have deployed / undeployed the bundle and
run it on my local machine.  Any ideas why this would not work?  I am
beginning to wonder if writing a custom processor and using xpath is the
right way to go, maybe I should be taking the message and just trying to
marshal them into the stubs provided with the web service wsdl that the
message comes from.  At any rate, here is the processor code thus far.

public void process(Exchange exchange) throws Exception {
        Document payload = exchange.getIn().getMandatoryBody(Document.class);
        
        NamespaceContext ctx = new NamespaceContext() {
            public String getNamespaceURI(String prefix) {
                String uri;
                
                if (prefix.equals("soap"))
                    uri = "http://schemas.xmlsoap.org/soap/envelope/";;
                else if (prefix.equals("ns1"))
                    uri =
"http://atp.abc.com/schema/common/ATPCommonServiceTypes/v1";;
                else if (prefix.equals("ns2"))
                    uri =
"http://atp.abc.com/schema/hotel/hcm/content/serviceDataTypes/v1";;
                else if (prefix.equals("ns3"))
                    uri =
"http://atp.abc.com/schema/hotel/hcm/content/dataTypes/v1";;
                else if (prefix.equals("ns4"))
                    uri =
"http://atp.abc.com/schema/common/content/serviceDataTypes/v1";;
                else
                    uri = null;
                return uri;
            }

          public String getPrefix(String namespaceURI) {return null;}
          public Iterator getPrefixes(String namespaceURI) {return null;}
        };
        
                XPath xpath = XPathFactory.newInstance().newXPath();
                xpath.setNamespaceContext(ctx);
            XPathExpression expr =
xpath.compile("//ns4:textLine[attributeNumber='719']");
                
            NodeList nodes = (NodeList)expr.evaluate(payload,
XPathConstants.NODESET);
            System.out.println("Node List length = " + nodes.getLength());
            
            for (int i = 0; i < nodes.getLength(); i++) {
                System.out.println(nodes.item(i).getNodeName() + " - " +
nodes.item(i).getNodeValue()); 
            }           


--
View this message in context: 
http://camel.465427.n5.nabble.com/Custom-Processor-with-XPath-tp5011728p5014112.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to