本文整理汇总了Java中org.w3c.dom.ls.LSInput.setStringData方法的典型用法代码示例。如果您正苦于以下问题:Java LSInput.setStringData方法的具体用法?Java LSInput.setStringData怎么用?Java LSInput.setStringData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.ls.LSInput
的用法示例。
在下文中一共展示了LSInput.setStringData方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLSInputParsingString
import org.w3c.dom.ls.LSInput; //导入方法依赖的package包/类
@Test
public void testLSInputParsingString() throws Exception {
DOMImplementationLS impl = (DOMImplementationLS) getDocumentBuilder().getDOMImplementation();
String xml = "<?xml version='1.0'?><test>runDocumentLS_Q6</test>";
LSParser domParser = impl.createLSParser(MODE_SYNCHRONOUS, null);
LSSerializer domSerializer = impl.createLSSerializer();
// turn off xml decl in serialized string for comparison
domSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE);
LSInput src = impl.createLSInput();
src.setStringData(xml);
assertEquals(src.getStringData(), xml);
Document doc = domParser.parse(src);
String result = domSerializer.writeToString(doc);
assertEquals(result, "<test>runDocumentLS_Q6</test>");
}
示例2: testInstanceResourceResolver
import org.w3c.dom.ls.LSInput; //导入方法依赖的package包/类
@Test
public void testInstanceResourceResolver() throws SAXException, IOException {
SchemaFactory f = factory();
Validator v = f.newSchema(charStreamSource(element("doc", element("inner")))).newValidator();
Assert.assertNull(v.getResourceResolver());
LSResourceResolver rr = new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
// In Java 5 Xerces absolutized the systemId relative to the current directory
int slashIndex = systemId.lastIndexOf('/');
if (slashIndex >= 0)
systemId = systemId.substring(slashIndex + 1);
Assert.assertEquals(systemId, "e.xml");
Assert.assertEquals(type, "http://www.w3.org/TR/REC-xml");
LSInput in = new LSInputImpl();
in.setStringData("<inner/>");
return in;
}
};
v.setResourceResolver(rr);
Assert.assertSame(v.getResourceResolver(), rr);
v.validate(charStreamSource("<!DOCTYPE doc [ <!ENTITY e SYSTEM 'e.xml'> ]><doc>&e;</doc>"));
}
示例3: testSchemaResourceResolver
import org.w3c.dom.ls.LSInput; //导入方法依赖的package包/类
@Test
public void testSchemaResourceResolver() throws SAXException, IOException {
SchemaFactory f = factory();
Assert.assertNull(f.getResourceResolver());
LSResourceResolver rr = new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
Assert.assertEquals(systemId, "myschema");
Assert.assertEquals(type, getLSType());
Assert.assertNull(baseURI);
Assert.assertNull(namespaceURI);
Assert.assertNull(publicId);
LSInput in = new LSInputImpl();
in.setStringData(createSchema("doc"));
return in;
}
};
f.setResourceResolver(rr);
Assert.assertSame(f.getResourceResolver(), rr);
Validator v = f.newSchema(charStreamSource(externalRef("myschema"))).newValidator();
v.validate(charStreamSource("<doc/>"));
}
示例4: normalizeXML
import org.w3c.dom.ls.LSInput; //导入方法依赖的package包/类
private static String normalizeXML(String xml) throws Exception {
// Remove all white space adjoining tags ("trim all elements")
xml = xml.replaceAll("\\s*<", "<");
xml = xml.replaceAll(">\\s*", ">");
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS domLS = (DOMImplementationLS) registry.getDOMImplementation("LS");
LSParser lsParser = domLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
LSInput input = domLS.createLSInput();
input.setStringData(xml);
Document document = lsParser.parse(input);
LSSerializer lsSerializer = domLS.createLSSerializer();
lsSerializer.getDomConfig().setParameter("comments", Boolean.FALSE);
lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
return lsSerializer.writeToString(document);
}
示例5: normalizeXML
import org.w3c.dom.ls.LSInput; //导入方法依赖的package包/类
/**
* Normalize and pretty-print XML so that it can be compared using string
* compare. The following code does the following: - Removes comments -
* Makes sure attributes are ordered consistently - Trims every element -
* Pretty print the document
*
* @param xml The XML to be normalized
* @return The equivalent XML, but now normalized
*/
public static String normalizeXML(String xml) throws Exception {
// Remove all white space adjoining tags ("trim all elements")
xml = xml.replaceAll("\\s*<", "<");
xml = xml.replaceAll(">\\s*", ">");
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS domLS = (DOMImplementationLS) registry.getDOMImplementation("LS");
LSParser lsParser = domLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
LSInput input = domLS.createLSInput();
input.setStringData(xml);
Document document = lsParser.parse(input);
LSSerializer lsSerializer = domLS.createLSSerializer();
lsSerializer.getDomConfig().setParameter("comments", Boolean.FALSE);
lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
return lsSerializer.writeToString(document);
}
示例6: getXmlSource
import org.w3c.dom.ls.LSInput; //导入方法依赖的package包/类
private LSInput getXmlSource(String xml1) {
LSInput src = implLS.createLSInput();
try {
if (xml1.endsWith(".xml"))
src.setByteStream(this.getClass().getResourceAsStream(XML_FILE_INTERNAL_DTD));
else
src.setStringData(xml1);
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception occured: " + e.getMessage());
}
return src;
}
示例7: getXmlSource
import org.w3c.dom.ls.LSInput; //导入方法依赖的package包/类
private LSInput getXmlSource(String xml1) {
LSInput src = implLS.createLSInput();
try {
src.setStringData(xml1);
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception occured: " + e.getMessage());
}
return src;
}
示例8: registerModel
import org.w3c.dom.ls.LSInput; //导入方法依赖的package包/类
/**
* registers bunch of node path's specified in the XML schema (XSD)
*
* @param model String; schema in plain text
* @throws BagriException in case of any error
*/
@Override
public void registerModel(String model) throws BagriException {
XSImplementation impl = (XSImplementation) new DOMXSImplementationSourceImpl().getDOMImplementation("XS-Loader LS");
XSLoader schemaLoader = impl.createXSLoader(null);
LSInput lsi = ((DOMImplementationLS) impl).createLSInput();
lsi.setStringData(model);
XSModel schema = schemaLoader.load(lsi);
processModel(schema);
}
示例9: getXmlSource
import org.w3c.dom.ls.LSInput; //导入方法依赖的package包/类
public LSInput getXmlSource(String xmldoc) {
LSInput srcdoc = createLSInput();
srcdoc.setStringData(xmldoc);
return srcdoc;
}
示例10: getXml1Source
import org.w3c.dom.ls.LSInput; //导入方法依赖的package包/类
public LSInput getXml1Source() {
LSInput src = createLSInput();
src.setStringData(xml1);
return src;
}
示例11: testCheckCharNorm001
import org.w3c.dom.ls.LSInput; //导入方法依赖的package包/类
/**
* Equivalence class partitioning with state and input values orientation
* for public void setParameter(String name, Object value) throws
* DOMException, <br>
* <b>pre-conditions</b>: the root element has one Text node with not fully
* normalized characters, the 'check-character-normalization' parameter set
* to true, <br>
* <b>name</b>: error-handler <br>
* <b>value</b>: DOMErrorHandler. <br>
* <b>Expected results</b>: LSParser calls the specified error handler
*/
@Test
public void testCheckCharNorm001() {
DOMImplementation domImpl = null;
try {
domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException pce) {
Assert.fail(pce.toString());
} catch (FactoryConfigurationError fce) {
Assert.fail(fce.toString());
}
DOMImplementationLS lsImpl = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");
if (lsImpl == null) {
System.out.println("OK, the DOM implementation does not support the LS 3.0");
return;
}
LSParser lsParser = lsImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
DOMConfiguration config = lsParser.getDomConfig();
if (!config.canSetParameter("check-character-normalization", Boolean.TRUE)) {
System.out.println("OK, setting 'check-character-normalization' to true is not supported");
return;
}
config.setParameter("check-character-normalization", Boolean.TRUE);
TestHandler testHandler = new TestHandler();
config.setParameter("error-handler", testHandler);
LSInput lsInput = lsImpl.createLSInput();
lsInput.setStringData("<root>\u0073\u0075\u0063\u0327\u006F\u006E</root>");
Document doc = lsParser.parse(lsInput);
if (null == testHandler.getError()) {
Assert.fail("no error is reported, expected 'check-character-normalization-failure'");
}
return; // Status.passed("OK");
}
示例12: testCheckCharNorm002
import org.w3c.dom.ls.LSInput; //导入方法依赖的package包/类
/**
* Equivalence class partitioning with state and input values orientation
* for public void setParameter(String name, Object value) throws
* DOMException, <br>
* <b>pre-conditions</b>: the root element contains a fully-normalized text, <br>
* <b>name</b>: check-character-normalization <br>
* <b>value</b>: false. <br>
* <b>Expected results</b>: LSParser reports no errors
*/
@Test
public void testCheckCharNorm002() {
DOMImplementation domImpl = null;
try {
domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException pce) {
Assert.fail(pce.toString());
} catch (FactoryConfigurationError fce) {
Assert.fail(fce.toString());
}
DOMImplementationLS lsImpl = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");
if (lsImpl == null) {
System.out.println("OK, the DOM implementation does not support the LS 3.0");
return;
}
LSParser lsParser = lsImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
DOMConfiguration config = lsParser.getDomConfig();
if (!config.canSetParameter("check-character-normalization", Boolean.FALSE)) {
Assert.fail("setting 'check-character-normalization' to false is not supported");
}
config.setParameter("check-character-normalization", Boolean.FALSE);
TestHandler testHandler = new TestHandler();
config.setParameter("error-handler", testHandler);
LSInput lsInput = lsImpl.createLSInput();
lsInput.setStringData("<root>fully-normalized</root>");
Document doc = lsParser.parse(lsInput);
if (null != testHandler.getError()) {
Assert.fail("no error is expected, but reported: " + testHandler.getError());
}
return; // Status.passed("OK");
}
示例13: parse
import org.w3c.dom.ls.LSInput; //导入方法依赖的package包/类
public static Document parse(String s, boolean validateIfSchema) {
DOMImplementationLS impl = getDOMImpl();
LSInput input = impl.createLSInput();
input.setStringData(s);
return parse(input, validateIfSchema);
}