本文整理汇总了Java中org.kxml2.kdom.Node.TEXT属性的典型用法代码示例。如果您正苦于以下问题:Java Node.TEXT属性的具体用法?Java Node.TEXT怎么用?Java Node.TEXT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.kxml2.kdom.Node
的用法示例。
在下文中一共展示了Node.TEXT属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recurseForOutput
private void recurseForOutput(Element e){
if(e.getChildCount() == 0) return;
for(int i=0;i<e.getChildCount();i++){
int kidType = e.getType(i);
if(kidType == Node.TEXT) { continue; }
if(e.getChild(i) instanceof String) { continue; }
Element kid = (Element)e.getChild(i);
//is just text
if(kidType == Node.ELEMENT && XFormUtils.isOutput(kid)){
String s = "${"+parseOutput(kid)+"}";
e.removeChild(i);
e.addChild(i, Node.TEXT, s);
//has kids? Recurse through them and swap output tag for parsed version
}else if(kid.getChildCount() !=0){
recurseForOutput(kid);
//is something else
}else{
continue;
}
}
}
示例2: getXMLText
/**
* reads all subsequent text nodes and returns the combined string
* needed because escape sequences are parsed into consecutive text nodes
* e.g. "abc&123" --> (abc)(&)(123)
**/
public static String getXMLText (Node node, int i, boolean trim) {
StringBuilder strBuff = null;
String text = node.getText(i);
if (text == null)
return null;
for (i++; i < node.getChildCount() && node.getType(i) == Node.TEXT; i++) {
if (strBuff == null)
strBuff = new StringBuilder(text);
strBuff.append(node.getText(i));
}
if (strBuff != null)
text = strBuff.toString();
if (trim)
text = text.trim();
return text;
}
示例3: getXMLText
/**
* reads all subsequent text nodes and returns the combined string
* needed because escape sequences are parsed into consecutive text nodes
* e.g. "abc&123" --> (abc)(&)(123)
*/
public static String getXMLText(Node node, int i, boolean trim) {
StringBuffer strBuff = null;
String text = node.getText(i);
if (text == null)
return null;
for (i++; i < node.getChildCount() && node.getType(i) == Node.TEXT; i++) {
if (strBuff == null)
strBuff = new StringBuffer(text);
strBuff.append(node.getText(i));
}
if (strBuff != null)
text = strBuff.toString();
if (trim)
text = text.trim();
return text;
}
示例4: getLabel
private String getLabel (Element e){
if(e.getChildCount() == 0) return null;
recurseForOutput(e);
StringBuilder sb = new StringBuilder();
for(int i = 0; i<e.getChildCount();i++){
if(e.getType(i)!=Node.TEXT && !(e.getChild(i) instanceof String)){
Object b = e.getChild(i);
Element child = (Element)b;
//If the child is in the HTML namespace, retain it.
if(NAMESPACE_HTML.equals(child.getNamespace())) {
sb.append(XFormSerializer.elementToString(child));
} else {
//Otherwise, ignore it.
System.out.println("Unrecognized tag inside of text: <" + child.getName() + ">. " +
"Did you intend to use HTML markup? If so, ensure that the element is defined in " +
"the HTML namespace.");
}
}else{
sb.append(e.getText(i));
}
}
String s = sb.toString().trim();
return s;
}
示例5: getLabel
private String getLabel(Element e) {
if (e.getChildCount() == 0) return null;
recurseForOutput(e);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < e.getChildCount(); i++) {
if (e.getType(i) != Node.TEXT && !(e.getChild(i) instanceof String)) {
Object b = e.getChild(i);
Element child = (Element)b;
//If the child is in the HTML namespace, retain it.
if (NAMESPACE_HTML.equals(child.getNamespace())) {
sb.append(XFormSerializer.elementToString(child));
} else {
//Otherwise, ignore it.
System.out.println("Unrecognized tag inside of text: <" + child.getName() + ">. " +
"Did you intend to use HTML markup? If so, ensure that the element is defined in " +
"the HTML namespace.");
}
} else {
sb.append(e.getText(i));
}
}
return sb.toString().trim();
}
示例6: recurseForOutput
private void recurseForOutput(Element e) {
if (e.getChildCount() == 0) return;
for (int i = 0; i < e.getChildCount(); i++) {
int kidType = e.getType(i);
if (kidType == Node.TEXT) {
continue;
}
if (e.getChild(i) instanceof String) {
continue;
}
Element kid = (Element)e.getChild(i);
//is just text
if (kidType == Node.ELEMENT && XFormUtils.isOutput(kid)) {
String s = "${" + parseOutput(kid) + "}";
e.removeChild(i);
e.addChild(i, Node.TEXT, s);
//has kids? Recurse through them and swap output tag for parsed version
} else if (kid.getChildCount() != 0) {
recurseForOutput(kid);
//is something else
} else {
continue;
}
}
}
示例7: buildInstanceStructure
/** parse instance hierarchy and turn into a skeleton model; ignoring data content, but respecting repeated nodes and 'template' flags */
public static TreeElement buildInstanceStructure(Element node, TreeElement parent, String instanceName, String docnamespace) {
TreeElement element = null;
//catch when text content is mixed with children
int numChildren = node.getChildCount();
boolean hasText = false;
boolean hasElements = false;
for (int i = 0; i < numChildren; i++) {
switch (node.getType(i)) {
case Node.ELEMENT:
hasElements = true;
break;
case Node.TEXT:
if (node.getText(i).trim().length() > 0)
hasText = true;
break;
}
}
if (hasElements && hasText) {
System.out.println("Warning: instance node '" + node.getName() + "' contains both elements and text as children; text ignored");
}
//check for repeat templating
String name = node.getName();
int multiplicity;
if (node.getAttributeValue(NAMESPACE_JAVAROSA, "template") != null) {
multiplicity = TreeReference.INDEX_TEMPLATE;
if (parent != null && parent.getChild(name, TreeReference.INDEX_TEMPLATE) != null) {
throw new XFormParseException("More than one node declared as the template for the same repeated set [" + name + "]", node);
}
} else {
multiplicity = (parent == null ? 0 : parent.getChildMultiplicity(name));
}
String modelType = node.getAttributeValue(NAMESPACE_JAVAROSA, "modeltype");
//create node; handle children
if (modelType == null) {
element = new TreeElement(name, multiplicity);
element.setInstanceName(instanceName);
} else {
if (typeMappings.get(modelType) == null) {
throw new XFormParseException("ModelType " + modelType + " is not recognized.", node);
}
element = new TreeElement(name, multiplicity);
}
if (node.getNamespace() != null) {
if (!node.getNamespace().equals(docnamespace)) {
element.setNamespace(node.getNamespace());
}
}
if (hasElements) {
for (int i = 0; i < numChildren; i++) {
if (node.getType(i) == Node.ELEMENT) {
element.addChild(buildInstanceStructure(node.getElement(i), element, instanceName, docnamespace));
}
}
}
//handle attributes
if (node.getAttributeCount() > 0) {
for (int i = 0; i < node.getAttributeCount(); i++) {
String attrNamespace = node.getAttributeNamespace(i);
String attrName = node.getAttributeName(i);
if (attrNamespace.equals(NAMESPACE_JAVAROSA) && attrName.equals("template")) {
continue;
}
if (attrNamespace.equals(NAMESPACE_JAVAROSA) && attrName.equals("recordset")) {
continue;
}
element.setAttribute(attrNamespace, attrName, node.getAttributeValue(i));
}
}
return element;
}