本文整理汇总了Java中org.w3c.dom.ProcessingInstruction类的典型用法代码示例。如果您正苦于以下问题:Java ProcessingInstruction类的具体用法?Java ProcessingInstruction怎么用?Java ProcessingInstruction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProcessingInstruction类属于org.w3c.dom包,在下文中一共展示了ProcessingInstruction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: print
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
protected void print(Node node, Map namespaces, boolean endWithComma) {
switch (node.getNodeType()) {
case Node.ELEMENT_NODE :
printElement((Element) node, namespaces, endWithComma);
break;
case Node.PROCESSING_INSTRUCTION_NODE :
printPI((ProcessingInstruction) node, endWithComma);
break;
case Node.TEXT_NODE :
printText((Text) node, endWithComma);
break;
case Node.COMMENT_NODE :
printComment((Comment) node, endWithComma);
break;
}
}
示例2: copy
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
public String copy(DatabaseObject dbo) throws EngineException {
clipboardDocument = XMLUtils.getDefaultDocumentBuilder().newDocument();
ProcessingInstruction pi = clipboardDocument.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"ISO-8859-1\"");
clipboardDocument.appendChild(pi);
clipboardRootElement = clipboardDocument.createElement("convertigo-clipboard");
clipboardDocument.appendChild(clipboardRootElement);
if (dbo != null) {
copyDatabaseObject(dbo);
}
String strObject = XMLUtils.prettyPrintDOM(clipboardDocument);
return strObject;
}
示例3: ecmaValue
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
String ecmaValue() {
// TODO See ECMA 357 Section 9.1
if (isTextType()) {
return ((org.w3c.dom.Text)dom).getData();
} else if (isAttributeType()) {
return ((org.w3c.dom.Attr)dom).getValue();
} else if (isProcessingInstructionType()) {
return ((org.w3c.dom.ProcessingInstruction)dom).getData();
} else if (isCommentType()) {
return ((org.w3c.dom.Comment)dom).getNodeValue();
} else if (isElementType()) {
throw new RuntimeException("Unimplemented ecmaValue() for elements.");
} else {
throw new RuntimeException("Unimplemented for node " + dom);
}
}
示例4: getStrFromNode
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
/**
* Method getStrFromNode
*
* @param xpathnode
* @return the string for the node.
*/
public static String getStrFromNode(Node xpathnode) {
if (xpathnode.getNodeType() == Node.TEXT_NODE) {
// we iterate over all siblings of the context node because eventually,
// the text is "polluted" with pi's or comments
StringBuilder sb = new StringBuilder();
for (Node currentSibling = xpathnode.getParentNode().getFirstChild();
currentSibling != null;
currentSibling = currentSibling.getNextSibling()) {
if (currentSibling.getNodeType() == Node.TEXT_NODE) {
sb.append(((Text) currentSibling).getData());
}
}
return sb.toString();
} else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) {
return ((Attr) xpathnode).getNodeValue();
} else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
return ((ProcessingInstruction) xpathnode).getNodeValue();
}
return null;
}
示例5: visit
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
private void visit( Node n ) throws SAXException {
setCurrentLocation( n );
// if a case statement gets too big, it should be made into a separate method.
switch(n.getNodeType()) {
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
String value = n.getNodeValue();
receiver.characters( value.toCharArray(), 0, value.length() );
break;
case Node.ELEMENT_NODE:
visit( (Element)n );
break;
case Node.ENTITY_REFERENCE_NODE:
receiver.skippedEntity(n.getNodeName());
break;
case Node.PROCESSING_INSTRUCTION_NODE:
ProcessingInstruction pi = (ProcessingInstruction)n;
receiver.processingInstruction(pi.getTarget(),pi.getData());
break;
}
}
示例6: serializePI
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
/**
* Serializes an ProcessingInstruction Node.
*
* @param node The ProcessingInstruction Node to serialize
*/
protected void serializePI(ProcessingInstruction node)
throws SAXException {
ProcessingInstruction pi = node;
String name = pi.getNodeName();
// well-formed=true
if ((fFeatures & WELLFORMED) != 0) {
isPIWellFormed(node);
}
// apply the LSSerializer filter
if (!applyFilter(node, NodeFilter.SHOW_PROCESSING_INSTRUCTION)) {
return;
}
// String data = pi.getData();
if (name.equals("xslt-next-is-raw")) {
fNextIsRaw = true;
} else {
this.fSerializer.processingInstruction(name, pi.getData());
}
}
示例7: test
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
@Test
public void test() throws Exception {
try {
ByteArrayInputStream bais = new ByteArrayInputStream("<?xmltarget foo?><test></test>".getBytes());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder xmlParser = factory.newDocumentBuilder();
// DOMParser p = new DOMParser();
Document document = xmlParser.parse(new InputSource(bais));
String result = ((ProcessingInstruction) document.getFirstChild()).getData();
System.out.println(result);
if (!result.equalsIgnoreCase("foo")) {
Assert.fail("missing PI data");
}
} catch (Exception e) {
}
}
示例8: testWProlog
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
@Test
public void testWProlog() throws Exception {
try {
ByteArrayInputStream bais = new ByteArrayInputStream("<?xml version=\"1.1\" encoding=\"UTF-8\"?><?xmltarget foo?><test></test>".getBytes());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder xmlParser = factory.newDocumentBuilder();
// DOMParser p = new DOMParser();
Document document = xmlParser.parse(new InputSource(bais));
String result = ((ProcessingInstruction) document.getFirstChild()).getData();
System.out.println(result);
if (!result.equalsIgnoreCase("foo")) {
Assert.fail("missing PI data");
}
} catch (Exception e) {
}
}
示例9: processingInstruction
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
public void processingInstruction (String target, String data)
throws SAXException
{
// we can't create populated entity ref nodes using
// only public DOM APIs (they've got to be readonly)
if (currentEntity != null)
return;
ProcessingInstruction pi;
if (isL2
// && consumer.isUsingNamespaces ()
&& target.indexOf (':') != -1)
namespaceError (
"PI target name is namespace nonconformant: "
+ target);
if (inDTD)
return;
pi = document.createProcessingInstruction (target, data);
top.appendChild (pi);
}
示例10: createProcessingInstruction
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
/**
* <b>DOM L1</b>
* Returns a newly created processing instruction.
*/
public ProcessingInstruction createProcessingInstruction(String target,
String data)
{
if (checkingCharacters)
{
boolean xml11 = "1.1".equals(version);
checkName(target, xml11);
if ("xml".equalsIgnoreCase(target))
{
throw new DomDOMException(DOMException.SYNTAX_ERR,
"illegal PI target name",
this, 0);
}
checkChar(data, xml11);
}
return new DomProcessingInstruction(this, target, data);
}
示例11: parseNode
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
protected static XNode parseNode(Node domNode) {
if (domNode instanceof Element) {
return XElement.parse((Element) domNode);
}
if (domNode instanceof Text) {
return new XText(((Text) domNode).getTextContent());
}
if (domNode instanceof Comment) {
return new XComment(((Comment) domNode).getTextContent());
}
if (domNode instanceof ProcessingInstruction) {
return new XProcessingInstruction(((ProcessingInstruction) domNode).getTarget(), ((ProcessingInstruction) domNode).getData());
}
if (domNode instanceof DocumentType) {
return new XDocumentType(((DocumentType) domNode).getName(), ((DocumentType) domNode).getInternalSubset());
}
throw new UnsupportedOperationException("implement " + domNode);
}
示例12: processingInstruction
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
public void processingInstruction (String target, String data)
throws SAXException
{
// we can't create populated entity ref nodes using
// only public DOM APIs (they've got to be readonly)
if (currentEntity != null)
return;
ProcessingInstruction pi;
if (isL2
// && consumer.isUsingNamespaces ()
&& target.indexOf (':') != -1)
namespaceError (
"PI target name is namespace nonconformant: "
+ target);
if (inDTD)
return;
pi = document.createProcessingInstruction (target, data);
top.appendChild (pi);
}
示例13: initRepository
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
protected Document initRepository ( final String processingType, final String type )
{
final Document doc = this.xml.create ();
{
final ProcessingInstruction pi = doc.createProcessingInstruction ( processingType, "version=\"1.1.0\"" );
doc.appendChild ( pi );
}
final Element root = doc.createElement ( "repository" );
doc.appendChild ( root );
root.setAttribute ( "name", this.title );
root.setAttribute ( "type", type );
root.setAttribute ( "version", "1" );
return doc;
}
示例14: loadNode
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
/**
* Loads the given node in the current sequence.
*
* @param node The W3C DOM node to load.
*
* @throws LoadingException If thrown while parsing.
*/
private void loadNode(Node node) throws LoadingException {
// dispatch to the correct loader performance: order by occurrence
if (node instanceof Element) {
load((Element)node);
}
if (node instanceof Text) {
load((Text)node);
} else if (node instanceof Attr) {
load((Attr)node);
} else if (node instanceof Document) {
load((Document)node);
} else if (node instanceof ProcessingInstruction) {
load((ProcessingInstruction)node);
// all other node types are ignored
}
}
示例15: visitNode
import org.w3c.dom.ProcessingInstruction; //导入依赖的package包/类
static <R> R visitNode(Node node, NodeVisitor<R> visitor) {
switch (node.getNodeType()) {
case Node.ELEMENT_NODE: return visitor.visitElement((Element) node);
case Node.ATTRIBUTE_NODE: return visitor.visitAttr((Attr) node);
case Node.TEXT_NODE: return visitor.visitText((Text) node);
case Node.CDATA_SECTION_NODE: return visitor.visitCDATASection((CDATASection) node);
case Node.ENTITY_REFERENCE_NODE: return visitor.visitEntityReference((EntityReference) node);
case Node.ENTITY_NODE: return visitor.visitEntity((Entity) node);
case Node.PROCESSING_INSTRUCTION_NODE:
return visitor.visitProcessingInstruction((ProcessingInstruction) node);
case Node.COMMENT_NODE: return visitor.visitComment((Comment) node);
case Node.DOCUMENT_NODE: return visitor.visitDocument((Document) node);
case Node.DOCUMENT_TYPE_NODE: return visitor.visitDocumentType((DocumentType) node);
case Node.DOCUMENT_FRAGMENT_NODE:
return visitor.visitDocumentFragment((DocumentFragment) node);
case Node.NOTATION_NODE: return visitor.visitNotation((Notation) node);
default: throw new RuntimeException();
}
}