In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Because in test_suite.xml, we use XInclude tags in many places, they are declared in a namespace called "http://www.w3.org/2001/XInclude", and the introduction part is declared with xi:include, and the purpose of our class is to insert and replace all of these parts with the imported files.
/ * * This class will handle converting a xinclude+xpointer marked xml file to a normal xml file * Because of the shortage of the current jdk, it only support the xPointer with element instead of NCName * @ author cwang58 * @ created date: Jun 10 2013 * / public class XIncludeConverter {/ * this method will handle change the XInclude+XPointer marked xml as normal xml * @ param origialXML the original xml which has the xInclude feature * @ return the parsedXML without the xInclude feature * / public static String convertXInclude2NormalXML (String originalXML) throws SAXException ParserConfigurationException,TransformerConfigurationException,IOException,TransformerException {DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance () / / open up the namespace aware so that it can recognize the "xi" namespace factory.setNamespaceAware (true); / / let this SAXParser support XInclude factory.setXIncludeAware (true); / / factory.setValidating (true); / / ignore all the comments added in the source document factory.setIgnoringComments (true); DocumentBuilder docBuilder = factory.newDocumentBuilder () Document doc = docBuilder.parse (new InputSource (new ByteArrayInputStream (originalXML.getBytes ("utf-8"); Transformer transformer = TransformerFactory.newInstance (). NewTransformer (); / / format the output xml string so it support indent and more readable transformer.setOutputProperty (OutputKeys.INDENT, "yes"); / / initialize StreamResult with File object to save to file StreamResult result = new StreamResult (new StringWriter ()) DOMSource source = new DOMSource (doc); transformer.transform (source, result); return result.getWriter (). ToString ();}
Here is an episode. In fact, in W3C, XInclude is often used in conjunction with Xpointer. Xpointer can help locate a small fragment of an object file instead of the whole target file. The location method can be element (), or xpointer (). If element, you can use (/ 1-2-3) this way to locate DOM, or based on id, the corresponding java parsing framework is xerce, but unfortunately, The latest version of the xerce framework only supports the positioning of element (/ 1 element 3 id 4 + 5). In the case of a schema-id-based approach, that is, when an id is declared, it cannot be located, but it may support this feature in the future.
Http://xerces.apache.org/xerces2-j/faq-xinclude.html#faq-8
Based on the above limitations, I decided to use only xi:include to include all files, then adjust locally, and bypass xpointer.
So the implementation code is shown above, in fact, since JDK 1.6, he has provided support for XInclude, which is internally delegated to xerce, which is step 3-4 corresponding to the architecture diagram.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.