本文整理汇总了Java中net.sf.saxon.type.Type.DOCUMENT属性的典型用法代码示例。如果您正苦于以下问题:Java Type.DOCUMENT属性的具体用法?Java Type.DOCUMENT怎么用?Java Type.DOCUMENT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类net.sf.saxon.type.Type
的用法示例。
在下文中一共展示了Type.DOCUMENT属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: NodeWrapper
/**
* This constructor is protected: nodes should be created using the wrap
* factory method on the DocumentWrapper class
*
* @param node
* The XOM node to be wrapped
* @param parent
* The NodeWrapper that wraps the parent of this node
* @param index
* Position of this node among its siblings
*/
protected NodeWrapper(Node node, NodeWrapper parent, int index) {
short kind;
if (node instanceof Element) {
kind = Type.ELEMENT;
} else if (node instanceof Text) {
kind = Type.TEXT;
} else if (node instanceof Attribute) {
kind = Type.ATTRIBUTE;
} else if (node instanceof Comment) {
kind = Type.COMMENT;
} else if (node instanceof ProcessingInstruction) {
kind = Type.PROCESSING_INSTRUCTION;
} else if (node instanceof Document) {
kind = Type.DOCUMENT;
} else {
throwIllegalNode(node); // moved out of fast path to enable better inlining
return; // keep compiler happy
}
this.nodeKind = kind;
this.node = node;
this.parent = parent;
this.index = index;
}
示例2: serializeItem
/**
* Serializes item after XPath or XQuery processor execution using Saxon.
*/
public static String serializeItem(Item item) throws XPathException {
if (item instanceof NodeInfo) {
int type = ((NodeInfo)item).getNodeKind();
if (type == Type.DOCUMENT || type == Type.ELEMENT) {
Properties props = new Properties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
props.setProperty(OutputKeys.INDENT, "yes");
StringWriter stringWriter = new java.io.StringWriter();
QueryResult.serialize((NodeInfo)item, new StreamResult(stringWriter), props);
stringWriter.flush();
return stringWriter.toString().replaceAll(" xmlns=\"http\\://www.w3.org/1999/xhtml\"", "");
}
}
return item.getStringValue();
}
示例3: toDOMDocument
@Converter
public static Document toDOMDocument(NodeInfo node) throws XPathException {
switch (node.getNodeKind()) {
case Type.DOCUMENT:
// DOCUMENT type nodes can be wrapped directly
return (Document) NodeOverNodeInfo.wrap(node);
case Type.ELEMENT:
// ELEMENT nodes need to build a new DocumentInfo before wrapping
Configuration config = node.getConfiguration();
DocumentInfo documentInfo = config.buildDocument(node);
return (Document) NodeOverNodeInfo.wrap(documentInfo);
default:
return null;
}
}
示例4: createDocumentFromNodeInfo
public static Document createDocumentFromNodeInfo(NodeInfo nodeInfo,
DiffXML.WhitespaceStrippingPolicy whitespaceHandling) throws ParserConfigurationException {
if (nodeInfo.getNodeKind() == Type.DOCUMENT) {
nodeInfo = nodeInfo.iterateAxis(AxisInfo.CHILD).next();
}
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setNamespaceAware(true);
docFactory.setValidating(false);
// docFactory.setExpandEntityReferences(true);
Document doc = docFactory.newDocumentBuilder().newDocument();
doc.setStrictErrorChecking(true); // TODO
doc.appendChild(createNodeFromNodeInfo(nodeInfo, doc, whitespaceHandling));
return doc;
}
示例5: selectID
/**
* Get the element with a given ID, if any
*
* @param id
* the required ID value
* @param getParent
* true if running the element-with-id() function rather than the id()
* function; the difference is that in the case of an element of type xs:ID,
* the parent of the element should be returned, not the element itself.
* @return the element with the given ID, or null if there is no such ID
* present (or if the parser has not notified attributes as being of
* type ID).
*/
public NodeInfo selectID(String id, boolean getParent) {
if (idIndex == null) {
Element elem;
switch (nodeKind) {
case Type.DOCUMENT :
elem = ((Document) node).getRootElement();
break;
case Type.ELEMENT :
elem = (Element) node;
break;
default:
return null;
}
idIndex = new HashMap(50);
buildIDIndex(elem);
}
NodeInfo result = (NodeInfo) idIndex.get(id);
if (result != null && getParent && result.isId() && result.getStringValue().equals(id)) {
result = result.getParent();
}
return result ;
}
示例6: iterateAxis
/**
* Return an enumeration over the nodes reached by the given axis from this node
*
* @param axisNumber The axis to be iterated over
* @param nodeTest A pattern to be matched by the returned nodes
* @return an AxisIterator that scans the nodes reached by the axis in turn.
*/
public AxisIterator iterateAxis(byte axisNumber, NodeTest nodeTest)
{
switch (axisNumber)
{
case Axis.ANCESTOR:
return new AncestorEnumeration(this, nodeTest, false);
case Axis.ANCESTOR_OR_SELF:
return new AncestorEnumeration(this, nodeTest, true);
case Axis.ATTRIBUTE:
if (this.getNodeKind() != Type.ELEMENT)
{
return EmptyIterator.getInstance();
}
return new AttributeEnumeration(this, nodeTest);
case Axis.CHILD:
if (this instanceof ParentNodeImpl)
{
return ((ParentNodeImpl)this).enumerateChildren(nodeTest);
}
else {
return EmptyIterator.getInstance();
}
case Axis.DESCENDANT:
if (getNodeKind() == Type.DOCUMENT &&
nodeTest instanceof NameTest &&
nodeTest.getPrimitiveType() == Type.ELEMENT)
{
return ((LazyDocument)this).getAllElements(nodeTest.getFingerprint());
}
else if (hasChildNodes()) {
return new DescendantEnumeration(this, nodeTest, false);
}
else {
return EmptyIterator.getInstance();
}
case Axis.DESCENDANT_OR_SELF:
return new DescendantEnumeration(this, nodeTest, true);
case Axis.FOLLOWING:
return new FollowingEnumeration(this, nodeTest);
case Axis.FOLLOWING_SIBLING:
return new FollowingSiblingEnumeration(this, nodeTest);
case Axis.NAMESPACE:
if (this.getNodeKind() != Type.ELEMENT)
{
return EmptyIterator.getInstance();
}
return NamespaceIterator.makeIterator(this, nodeTest);
case Axis.PARENT:
NodeInfo parent = getParent();
if (parent == null) {
return EmptyIterator.getInstance();
}
return Navigator.filteredSingleton(parent, nodeTest);
case Axis.PRECEDING:
return new PrecedingEnumeration(this, nodeTest);
case Axis.PRECEDING_SIBLING:
return new PrecedingSiblingEnumeration(this, nodeTest);
case Axis.SELF:
return Navigator.filteredSingleton(this, nodeTest);
case Axis.PRECEDING_OR_ANCESTOR:
return new PrecedingOrAncestorEnumeration(this, nodeTest);
default:
throw new IllegalArgumentException("Unknown axis number " + axisNumber);
}
}
示例7: getNodeKind
/**
* Returns type of the node.
* @return node kind
*/
@Override
public int getNodeKind() {
return Type.DOCUMENT;
}
示例8: unwrapNodeInfo
protected NodeInfo unwrapNodeInfo(NodeInfo nodeInfo) {
if (nodeInfo != null && nodeInfo.getNodeKind() == Type.DOCUMENT) {
nodeInfo = nodeInfo.iterateAxis(AxisInfo.CHILD, NodeKindTest.ELEMENT).next();
}
return nodeInfo;
}
示例9: buildSegments
private static LinkedList<ContentPathSegment<?, ?>> buildSegments(LinkedList<ContentPathSegment<?, ?>> segments, NodeInfo nodeInfo,
@Nullable String nsPrefix, @Nullable String nsUri, String localName) {
boolean attrNode = (nodeInfo.getNodeKind() == Type.ATTRIBUTE);
if (attrNode) {
segments.add(0, new AttributePathSegmentImpl(nsPrefix, nsUri, localName));
}
ElementPathSegment elemSegment = new ElementPathSegmentImpl(nsPrefix, nsUri, localName);
segments.add(0, elemSegment);
NodeInfo parentNodeInfo = nodeInfo.getParent();
if ((parentNodeInfo != null) && (parentNodeInfo.getNodeKind() != Type.DOCUMENT)) {
if (!attrNode) {
int nodeIndex = -1;
SameNameTest siblingNodeTest = new SameNameTest(nodeInfo);
AxisIterator precedingSiblingNodeIterator = nodeInfo.iterateAxis(AxisInfo.PRECEDING_SIBLING, siblingNodeTest);
while (precedingSiblingNodeIterator.next() != null) {
nodeIndex++;
}
if (nodeIndex == -1) {
if (nodeInfo.iterateAxis(AxisInfo.FOLLOWING_SIBLING, siblingNodeTest).next() != null) {
nodeIndex = 0;
}
} else {
nodeIndex++;
}
if (nodeIndex >= 0) {
elemSegment.setIndex(nodeIndex);
}
}
buildSegments(segments, parentNodeInfo, parentNodeInfo.getPrefix(), parentNodeInfo.getURI(), parentNodeInfo.getLocalPart());
}
return segments;
}
示例10: getNodeKind
/**
* Get the type of node this document is -- ie it's a document node.
*/
public int getNodeKind() {
return Type.DOCUMENT;
}
示例11: getItemType
/**
* Return the type of node.
* @return Type.DOCUMENT (always)
*/
public final int getItemType() {
return Type.DOCUMENT;
}