Methods Summary |
---|
public static java.lang.String | getAttribute(org.w3c.dom.Element element, java.lang.String attributeName, java.lang.String deflt)
String result=element.getAttribute(attributeName);
if( (result==null)|| ("".equals(result) ) )
{
return deflt;
}
return result;
|
public static float | getAttribute(org.w3c.dom.Element element, java.lang.String attributeName, float deflt)
String result=element.getAttribute(attributeName);
if( (result==null)|| ("".equals(result) ) )
{
return deflt;
}
return Float.parseFloat(result);
|
public static int | getAttribute(org.w3c.dom.Element element, java.lang.String attributeName, int deflt)
String result=element.getAttribute(attributeName);
if( (result==null)|| ("".equals(result) ) )
{
return deflt;
}
return Integer.parseInt(result);
|
public static boolean | getAttribute(org.w3c.dom.Element element, java.lang.String attributeName, boolean deflt)
String result = element.getAttribute(attributeName);
if ((result == null) || ("".equals(result)))
{
return deflt;
}
return Boolean.getBoolean(result);
|
public static java.lang.String | getAttributeOrFail(org.w3c.dom.Element e, java.lang.String name)
String v = e.getAttribute(name);
if (null == v)
{
throw new ParserException(e.getTagName() + " missing \"" + name
+ "\" attribute");
}
return v;
|
public static java.lang.String | getAttributeWithInheritance(org.w3c.dom.Element element, java.lang.String attributeName)Returns an attribute value from this node, or first parent node with this attribute defined
String result=element.getAttribute(attributeName);
if( (result==null)|| ("".equals(result) ) )
{
Node n=element.getParentNode();
if((n==element)||(n==null))
{
return null;
}
Element parent=(Element) n;
return getAttributeWithInheritance(parent,attributeName);
}
return result;
|
public static java.lang.String | getAttributeWithInheritanceOrFail(org.w3c.dom.Element e, java.lang.String name)
String v = getAttributeWithInheritance(e, name);
if (null == v)
{
throw new ParserException(e.getTagName() + " missing \"" + name
+ "\" attribute");
}
return v;
|
public static org.w3c.dom.Element | getChildByTagName(org.w3c.dom.Element e, java.lang.String name)
for (Node kid = e.getFirstChild(); kid != null; kid = kid.getNextSibling())
{
if( (kid.getNodeType()==Node.ELEMENT_NODE) && (name.equals(kid.getNodeName())) )
{
return (Element)kid;
}
}
return null;
|
public static org.w3c.dom.Element | getChildByTagOrFail(org.w3c.dom.Element e, java.lang.String name)
Element kid = getChildByTagName(e, name);
if (null == kid)
{
throw new ParserException(e.getTagName() + " missing \"" + name
+ "\" child element");
}
return kid;
|
public static java.lang.String | getChildTextByTagName(org.w3c.dom.Element e, java.lang.String tagName)
Element child=getChildByTagName(e,tagName);
if(child!=null)
{
return getText(child);
}
return null;
|
public static org.w3c.dom.Element | getFirstChildElement(org.w3c.dom.Element element)
for (Node kid = element.getFirstChild(); kid != null; kid = kid
.getNextSibling())
{
if (kid.getNodeType() == Node.ELEMENT_NODE)
{
return (Element) kid;
}
}
return null;
|
public static org.w3c.dom.Element | getFirstChildOrFail(org.w3c.dom.Element e)
Element kid = getFirstChildElement(e);
if (null == kid)
{
throw new ParserException(e.getTagName()
+ " does not contain a child element");
}
return kid;
|
public static java.lang.String | getNonBlankTextOrFail(org.w3c.dom.Element e)
String v = getText(e);
if (null != v)
v = v.trim();
if (null == v || 0 == v.length())
{
throw new ParserException(e.getTagName() + " has no text");
}
return v;
|
public static java.lang.String | getText(org.w3c.dom.Node e)
StringBuffer sb=new StringBuffer();
getTextBuffer(e, sb);
return sb.toString();
|
private static void | getTextBuffer(org.w3c.dom.Node e, java.lang.StringBuffer sb)
for (Node kid = e.getFirstChild(); kid != null; kid = kid.getNextSibling())
{
switch(kid.getNodeType())
{
case Node.TEXT_NODE:
{
sb.append(kid.getNodeValue());
break;
}
case Node.ELEMENT_NODE:
{
getTextBuffer(kid, sb);
break;
}
case Node.ENTITY_REFERENCE_NODE:
{
getTextBuffer(kid, sb);
break;
}
}
}
|
public static org.w3c.dom.Element | insertChild(org.w3c.dom.Element parent, java.lang.String tagName, java.lang.String text)
Element child = parent.getOwnerDocument().createElement(tagName);
parent.appendChild(child);
if(text!=null)
{
child.appendChild(child.getOwnerDocument().createTextNode(text));
}
return child;
|
public static org.w3c.dom.Document | loadXML(java.io.Reader is)Helper method to parse an XML file into a DOM tree, given a filename.
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
try
{
db = dbf.newDocumentBuilder();
}
catch (Exception se)
{
throw new RuntimeException("Parser configuration error", se);
}
// Step 3: parse the input file
org.w3c.dom.Document doc = null;
try
{
doc = db.parse(new InputSource(is));
//doc = db.parse(is);
}
catch (Exception se)
{
throw new RuntimeException("Error parsing file:" + se, se);
}
return doc;
|