use of com.helger.xml.microdom.IMicroElement in project ph-schematron by phax.
the class PSReader method readActiveFromXML.
/**
* Read an <active> element
*
* @param eActive
* The source micro element. Never <code>null</code>.
* @return The created domain object. May not be <code>null</code>.
*/
@Nonnull
public PSActive readActiveFromXML(@Nonnull final IMicroElement eActive) {
final PSActive ret = new PSActive();
eActive.forAllAttributes((sNS, sAttrName, sVal) -> {
final String sAttrValue = _getAttributeValue(sVal);
if (sAttrName.equals(CSchematronXML.ATTR_PATTERN))
ret.setPattern(sAttrValue);
else
ret.addForeignAttribute(sAttrName, sAttrValue);
});
eActive.forAllChildren(aActiveChild -> {
switch(aActiveChild.getType()) {
case TEXT:
ret.addText(((IMicroText) aActiveChild).getNodeValue());
break;
case ELEMENT:
final IMicroElement eElement = (IMicroElement) aActiveChild;
if (CSchematron.NAMESPACE_SCHEMATRON.equals(eElement.getNamespaceURI())) {
final String sLocalName = eElement.getLocalName();
if (sLocalName.equals(CSchematronXML.ELEMENT_DIR))
ret.addDir(readDirFromXML(eElement));
else if (sLocalName.equals(CSchematronXML.ELEMENT_EMPH))
ret.addEmph(readEmphFromXML(eElement));
else if (sLocalName.equals(CSchematronXML.ELEMENT_SPAN))
ret.addSpan(readSpanFromXML(eElement));
else
_warn(ret, "Unsupported Schematron element '" + sLocalName + "'");
} else
ret.addForeignElement(eElement.getClone());
break;
case COMMENT:
// Ignore comments
break;
default:
_warn(ret, "Unsupported child node: " + aActiveChild);
}
});
return ret;
}
use of com.helger.xml.microdom.IMicroElement in project ph-schematron by phax.
the class PSReader method readTitleFromXML.
/**
* Read a <title> element
*
* @param eTitle
* The source micro element. Never <code>null</code>.
* @return The created domain object. May not be <code>null</code>.
*/
@Nonnull
public PSTitle readTitleFromXML(@Nonnull final IMicroElement eTitle) {
final PSTitle ret = new PSTitle();
eTitle.forAllAttributes((sNS, sAttrName, sVal) -> {
final String sAttrValue = _getAttributeValue(sVal);
_warn(ret, "Unsupported attribute '" + sAttrName + "'='" + sAttrValue + "'");
});
eTitle.forAllChildren(aTitleChild -> {
switch(aTitleChild.getType()) {
case TEXT:
ret.addText(((IMicroText) aTitleChild).getNodeValue());
break;
case ELEMENT:
final IMicroElement eElement = (IMicroElement) aTitleChild;
if (CSchematron.NAMESPACE_SCHEMATRON.equals(eElement.getNamespaceURI())) {
final String sLocalName = eElement.getLocalName();
if (sLocalName.equals(CSchematronXML.ELEMENT_DIR))
ret.addDir(readDirFromXML(eElement));
else
_warn(ret, "Unsupported Schematron element '" + sLocalName + "'");
} else
_warn(ret, "Unsupported namespace URI '" + eElement.getNamespaceURI() + "'");
break;
case COMMENT:
// Ignore comments
break;
default:
_warn(ret, "Unsupported child node: " + aTitleChild);
}
});
return ret;
}
use of com.helger.xml.microdom.IMicroElement in project ph-schematron by phax.
the class PSReader method readDiagnosticFromXML.
/**
* Read a <diagnostic> element
*
* @param eDiagnostic
* The source micro element. Never <code>null</code>.
* @return The created domain object. May not be <code>null</code>.
*/
@Nonnull
public PSDiagnostic readDiagnosticFromXML(@Nonnull final IMicroElement eDiagnostic) {
final PSDiagnostic ret = new PSDiagnostic();
final PSRichGroup aRichGroup = new PSRichGroup();
eDiagnostic.forAllAttributes((sNS, sAttrName, sVal) -> {
final String sAttrValue = _getAttributeValue(sVal);
if (sAttrName.equals(CSchematronXML.ATTR_ID))
ret.setID(sAttrValue);
else if (PSRichGroup.isRichAttribute(sAttrName))
_handleRichGroup(sAttrName, sAttrValue, aRichGroup);
else
ret.addForeignAttribute(sAttrName, sAttrValue);
});
ret.setRich(aRichGroup);
eDiagnostic.forAllChildren(aDiagnosticChild -> {
switch(aDiagnosticChild.getType()) {
case TEXT:
ret.addText(((IMicroText) aDiagnosticChild).getNodeValue());
break;
case ELEMENT:
final IMicroElement eElement = (IMicroElement) aDiagnosticChild;
if (CSchematron.NAMESPACE_SCHEMATRON.equals(eElement.getNamespaceURI())) {
final String sLocalName = eElement.getLocalName();
if (sLocalName.equals(CSchematronXML.ELEMENT_VALUE_OF))
ret.addValueOf(readValueOfFromXML(eElement));
else if (sLocalName.equals(CSchematronXML.ELEMENT_EMPH))
ret.addEmph(readEmphFromXML(eElement));
else if (sLocalName.equals(CSchematronXML.ELEMENT_DIR))
ret.addDir(readDirFromXML(eElement));
else if (sLocalName.equals(CSchematronXML.ELEMENT_SPAN))
ret.addSpan(readSpanFromXML(eElement));
else
_warn(ret, "Unsupported Schematron element '" + sLocalName + "'");
} else
ret.addForeignElement(eElement.getClone());
break;
case COMMENT:
// Ignore comments
break;
default:
_warn(ret, "Unsupported child node: " + aDiagnosticChild);
}
});
return ret;
}
use of com.helger.xml.microdom.IMicroElement in project ph-schematron by phax.
the class PSReader method readSpanFromXML.
/**
* Read a <span> element
*
* @param eSpan
* The source micro element. Never <code>null</code>.
* @return The created domain object. May not be <code>null</code>.
*/
@Nonnull
public PSSpan readSpanFromXML(@Nonnull final IMicroElement eSpan) {
final PSSpan ret = new PSSpan();
eSpan.forAllAttributes((sNS, sAttrName, sVal) -> {
final String sAttrValue = _getAttributeValue(sVal);
if (sAttrName.equals(CSchematronXML.ATTR_CLASS))
ret.setClazz(sAttrValue);
else
ret.addForeignAttribute(sAttrName, sAttrValue);
});
eSpan.forAllChildren(aSpanChild -> {
switch(aSpanChild.getType()) {
case TEXT:
ret.addText(((IMicroText) aSpanChild).getNodeValue());
break;
case ELEMENT:
final IMicroElement eElement = (IMicroElement) aSpanChild;
if (CSchematron.NAMESPACE_SCHEMATRON.equals(eElement.getNamespaceURI())) {
_warn(ret, "Unsupported Schematron element '" + eElement.getLocalName() + "'");
} else
ret.addForeignElement(eElement.getClone());
break;
case COMMENT:
// Ignore comments
break;
default:
_warn(ret, "Unsupported child node: " + aSpanChild);
}
});
return ret;
}
use of com.helger.xml.microdom.IMicroElement in project ph-schematron by phax.
the class PSReader method readPFromXML.
/**
* Read a <p> element
*
* @param eP
* The source micro element. Never <code>null</code>.
* @return The created domain object. May not be <code>null</code>.
*/
@Nonnull
public PSP readPFromXML(@Nonnull final IMicroElement eP) {
final PSP ret = new PSP();
eP.forAllAttributes((sNS, sAttrName, sVal) -> {
final String sAttrValue = _getAttributeValue(sVal);
if (sAttrName.equals(CSchematronXML.ATTR_ID))
ret.setID(sAttrValue);
else if (sAttrName.equals(CSchematronXML.ATTR_CLASS))
ret.setClazz(sAttrValue);
else if (sAttrName.equals(CSchematronXML.ATTR_ICON))
ret.setIcon(sAttrValue);
else
ret.addForeignAttribute(sAttrName, sAttrValue);
});
eP.forAllChildren(aChild -> {
switch(aChild.getType()) {
case TEXT:
ret.addText(((IMicroText) aChild).getNodeValue());
break;
case ELEMENT:
final IMicroElement eElement = (IMicroElement) aChild;
if (CSchematron.NAMESPACE_SCHEMATRON.equals(eElement.getNamespaceURI())) {
final String sLocalName = eElement.getLocalName();
if (sLocalName.equals(CSchematronXML.ELEMENT_DIR))
ret.addDir(readDirFromXML(eElement));
else if (sLocalName.equals(CSchematronXML.ELEMENT_EMPH))
ret.addEmph(readEmphFromXML(eElement));
else if (sLocalName.equals(CSchematronXML.ELEMENT_SPAN))
ret.addSpan(readSpanFromXML(eElement));
else
_warn(ret, "Unsupported Schematron element '" + sLocalName + "'");
} else
ret.addForeignElement(eElement.getClone());
break;
case COMMENT:
// Ignore comments
break;
default:
_warn(ret, "Unsupported child node: " + aChild);
}
});
return ret;
}
Aggregations