public class readBytes{ public static void main(String[] s} throws VTDException{ VTDGen vg = new VTDGen(); //get XML Byte array here vg.setDoc(xmlByteArray); vg.parse(); VTDNav vn = vg.getNav(); } }
import com.ximpleware.*; import java.io.*; public class removeAttrNode { public static void main(String[] s) throws VTDException, Exception{ VTDGen vg = new VTDGen(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Payment xmlns=\"http://api.com/schema/store/1.0\"><Store>abc</Store></Payment>"; vg.setDoc(xml.getBytes()); vg.parse(false); // turn off namespace awareness so that VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); XMLModifier xm = new XMLModifier(vn); ap.selectXPath("//@xmlns"); int i=0; while((i=ap.evalXPath())!=-1){ xm.remove(); } xm.output(baos); System.out.println(baos.toString()); } }
import com.ximpleware.*; public class simpleQuery { public static void main(String[] s) throws Exception{ String myXML="<resp><status>good</status><msg>hi</msg></resp>"; VTDGen vg = new VTDGen(); vg.setDoc(myXML.getBytes()); vg.parse(false); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/resp/status"); int i = ap.evalXPath(); if (i!=-1) System.out.println(" result ==>"+vn.toString(i)); } }
public void parse(byte[] data, byte[] identifier, JCas jcas) { try { VTDGen vg = new VTDGen(); // needed for extraction of mixed-content-XML // when there is a whitespace only between two // tags, e.g. ...</s> <s id=".">... vg.enableIgnoredWhiteSpace(true); vg.setDoc(data); vg.parse(true); VTDNav vn = vg.getNav(); buildTypes(identifier, jcas, vn); } catch (EncodingException e) { e.printStackTrace(); } catch (EOFException e) { e.printStackTrace(); } catch (EntityException e) { LOG.error(String.format("Document %s could not be parsed due to an EntityError. Document text is:\n%s", new String(identifier), new String(data)), e); } catch (CollectionException e) { e.printStackTrace(); } catch (ParseException e) { LOG.error(String.format("Document %s could not be parsed due to a general parsing error. Document text is:\n%s", new String(identifier), new String(data)), e); } }
import com.ximpleware.*; public class queryNS { public static void main(String[] args) throws VTDException { // TODO Auto-generated method stub VTDGen vg = new VTDGen(); String xml = "<test xmlns='xyz'><a/></test>"; byte[] ba = xml.getBytes(); vg.setDoc(ba); vg.parse(true); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/test/namespace::node()"); int i=0; while((i=ap.evalXPath())!=-1){ System.out.println(" value ===>"+vn.toString(i+1)); } } }
@Override public XmiSplitterResult process(byte[] xmiData, JCas aCas, int nextPossibleId, Map<String, Integer> existingSofaIdMap) throws XMISplitterException { VTDGen vg = new VTDGen(); vg.setDoc(xmiData); try { vg.parse(true); vn = vg.getNav(); log.debug("Building namespace map"); Map<String, String> namespaceMap = JulieXMLTools.buildNamespaceMap(vn); log.debug("Creating JeDIS nodes"); nodesByXmiId = createJedisNodes(vn, namespaceMap, aCas); log.debug("Labeling nodes"); labelNodes(nodesByXmiId, moduleAnnotationNames, recursively); log.debug("Creating annotation modules"); annotationModules = createAnnotationModules(nodesByXmiId); log.debug("Assigning new XMI IDs"); ImmutablePair<Integer, Map<String, Integer>> nextXmiIdAndSofaMap = assignNewXmiIds(nodesByXmiId, existingSofaIdMap, nextPossibleId); log.debug("Slicing XMI data into annotation module data"); LinkedHashMap<String, ByteArrayOutputStream> moduleData = createAnnotationModuleData(nodesByXmiId, annotationModules); Map<Integer, String> reverseSofaIdMap = nextXmiIdAndSofaMap.right.entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey)); log.debug("Returning XMI annotation module result"); return new XmiSplitterResult(moduleData, nextXmiIdAndSofaMap.left, namespaceMap, reverseSofaIdMap); } catch (VTDException e) { throw new XMISplitterException(e); } }
"</EMpData>\n"; vg.setDoc(xml.getBytes()); vg.parse(false); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn);
/** * Gets the XML document. * * @param is the input stream * @param request the request * @return the XML document * @throws Exception the exception */ protected VTDNav getVTDXmlDocument(InputStream is, Request request) throws Exception { is = preProcessHtml(request, is); is = applyXsltTransformation(request, is); VTDGen vg = new VTDGen(); vg.setDoc(IOUtils.toByteArray(is)); vg.parse(true); final VTDNav nav = vg.getNav(); return nav; }
import com.ximpleware.*; public class concatTest{ public static void main(String s1[]) throws Exception { VTDGen vg= new VTDGen(); String s = "<users><user><firstName>some </firstName><lastName> one</lastName></user></users>"; vg.setDoc(s.getBytes()); vg.parse(false); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/users/user/firstName"); int i=ap.evalXPath(); if (i!=1){ long l= vn.getElementFragment(); System.out.println(" the segment is "+ vn.toString((int)l,(int)(l>>32))); } } }
vg.setDoc(message.getBytes()); vg.parse(true);
public static String getXpathValue(String xpath, InputStream is) throws IOException, XPathParseException, ParseException { VTDGen vg = new VTDGen(); vg.setDoc(readStream(is, 1024)); vg.parse(false); return getXpathValue(xpath, vg.getNav()); }
import com.ximpleware.*; public class concatTest{ public static void main(String s1[]) throws Exception { VTDGen vg= new VTDGen(); String s = "<users><user><firstName>some </firstName><lastName> one</lastName></user></users>"; vg.setDoc(s.getBytes()); vg.parse(false); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(); ap.selectXPath("concat('good', ' luck')"); System.out.println(" concat output ==>"+ap.evalXPathToString()); ap.selectXPath("concat(/, '')"); ap.bind(vn); System.out.println(" concat output ==>"+ap.evalXPathToString()); } }
generator.parse(false);
VTDGen vg = new VTDGen(); vg.setDoc(data); vg.parse(true); VTDNav vn = vg.getNav(); return constructRowIterator(vn, forEachXpath, fields, identifier);
public static VTDNav getVTDNav(InputStream is, int bufferSize) throws ParseException, FileTooBigException { VTDGen vg = null; try { byte[] data = readStream(is, bufferSize); vg = new VTDGen(); vg.setDoc(data); vg.parse(true); } catch (EncodingException e) { e.printStackTrace(); } catch (EOFException e) { e.printStackTrace(); } catch (EntityException e) { e.printStackTrace(); } catch (FileTooBigException e) { throw e; } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { String message = e.getMessage(); if (message.contains("file size too big")) throw new FileTooBigException(message); } return vg.getNav(); }
/** * outAndReparse writes updated XML content into a new byte * array, then parse and return a new VTDNav object * @return VTDNav encapsulating update XML documents * @throws ParseException * @throws IOException * @throws TranscodeException * @throws ModifyException */ public VTDNav outputAndReparse() throws ParseException, IOException,TranscodeException,ModifyException{ XMLByteOutputStream xbos = new XMLByteOutputStream(getUpdatedDocumentSize()); output(xbos); VTDGen vg = new VTDGen(); vg.setDoc(xbos.getXML()); vg.parse(this.md.ns); return vg.getNav(); }
/** * outAndReparse writes updated XML content into a new byte * array, then parse and return a new VTDNav object * @return VTDNav encapsulating update XML documents * @throws ParseException * @throws IOException * @throws TranscodeException * @throws ModifyException */ public VTDNav outputAndReparse() throws ParseException, IOException,TranscodeException,ModifyException{ XMLByteOutputStream xbos = new XMLByteOutputStream(getUpdatedDocumentSize()); output(xbos); VTDGen vg = new VTDGen(); vg.setDoc(xbos.getXML()); vg.parse(this.md.ns); return vg.getNav(); }
/** * outAndReparse writes updated XML content into a new byte * array, then parse and return a new VTDNav object * @return VTDNav encapsulating update XML documents * @throws ParseException * @throws IOException * @throws TranscodeException * @throws ModifyException */ public VTDNav outputAndReparse() throws ParseException, IOException,TranscodeException,ModifyException{ XMLByteOutputStream xbos = new XMLByteOutputStream(getUpdatedDocumentSize()); output(xbos); VTDGen vg = new VTDGen(); vg.setDoc(xbos.getXML()); vg.parse(this.md.ns); return vg.getNav(); }
public void reset(InputStream is, JCas cas) throws DocumentParsingException { this.cas = cas; try { byte[] bytes = JulieXMLTools.readStream(is, 8192); VTDGen vg = new VTDGen(); vg.setDoc(bytes); // If we don't set this to true, some whitespaces, for example // directly after closing tags, would be omitted. We don't want // this, the NXML format is very specific in its whitespaces. vg.enableIgnoredWhiteSpace(true); vg.parse(false); vn = vg.getNav(); setTagset(); setupParserRegistry(); } catch (IOException | VTDException e) { throw new DocumentParsingException(e); } }
@Override public void index() throws Exception { super.index(); // Parse use VTD-XML vg = new VTDGen(); vg.setDoc(inputDocument); // Whitespace in between elements is normally ignored, // but we explicitly allow whitespace in between elements to be collected here. // This allows punctuation xpath to match this whitespace, in case punctuation/whitespace in the document isn't contained in a dedicated element or attribute. // This doesn't mean that this whitespace is always used, it just enables the punctuation xpath to find this whitespace if it explicitly matches it. vg.enableIgnoredWhiteSpace(true); vg.parse(config.isNamespaceAware()); nav = vg.getNav(); // Find all documents AutoPilot documents = acquireAutoPilot(config.getDocumentPath()); while(documents.evalXPath() != -1) { indexDocument(); } releaseAutoPilot(documents); }