/** * Declares the given namespaces to the passed auto pilot. The <tt>namespaceMap</tt> * can automatically be derived from an XML document by calling {@link #buildNamespaceMap(VTDNav)}. * * @param ap * @param namespaceMap */ public static void declareNamespaces(AutoPilot ap, Map<String, String> namespaceMap) { for (Map.Entry<String, String> entry : namespaceMap.entrySet()) ap.declareXPathNameSpace(entry.getKey(), entry.getValue()); }
AutoPilot ap = new AutoPilot(nav); ap.declareXPathNameSpace("h", "urn:hypotheticalNamespace"); ap.declareXPathNameSpace("xql", "someNameSpace"); ap.selectXPath("/h:startQuery/xql:XQL");
AutoPilot ap = new AutoPilot(nav); ap.declareXPathNameSpace("xql", "someNameSpace"); ap.selectXPath("/startQuery/xql:XQL");
AutoPilot ap = new AutoPilot(nav); ap.declareXPathNameSpace("xql", "someNameSpace"); ap.selectXPath("//xql:XQL");
/** * Create AutoPilot and declare namespaces on it. * @param xpathExpr xpath expression for the AutoPilot * @return the AutoPilot * @throws XPathParseException */ private AutoPilot acquireAutoPilot(String xpathExpr) throws XPathParseException { AutoPilot ap = compiledXPaths.remove(xpathExpr); if (ap == null) { ap = new AutoPilot(nav); if (config.isNamespaceAware()) { ap.declareXPathNameSpace("xml", "http://www.w3.org/XML/1998/namespace"); // builtin for (Entry<String, String> e: config.getNamespaces().entrySet()) { ap.declareXPathNameSpace(e.getKey(), e.getValue()); } } try { ap.selectXPath(xpathExpr); } catch (XPathParseException e) { throw new RuntimeException("Error in XPath expression " + xpathExpr + " : " + e.getMessage(), e); } } else { ap.resetXPath(); } autoPilotsInUse.put(ap, xpathExpr); return ap; }
ap.declareXPathNameSpace("ns", "http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema"); ap.declareXPathNameSpace("ns1", "http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema"); ap.declareXPathNameSpace("cm", "http://www.ibm.com/xmlns/db2/cm/api/1.0/schema"); ap.declareXPathNameSpace("soapenv", "http://www.w3.org/2003/05/soap-envelope");
import com.ximpleware.*; import java.io.*; public class updateXSD { public static void main(String[] s) throws VTDException, IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("d:\\xml\\xsd.xml", true)){ return; } VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.declareXPathNameSpace("xs", "XSD namespace here"); ap.selectXPath("//xs:element[@name='Bike']/@type"); XMLModifier xm = new XMLModifier(vn); int i=-1; while((i=ap.evalXPath())!=-1){ xm.updateToken(i+1, "Twowheeler"); } xm.output("d:\\xml\\newXSD.xml"); } }