本文整理汇总了Java中com.helger.xml.microdom.IMicroDocument.getDocumentElement方法的典型用法代码示例。如果您正苦于以下问题:Java IMicroDocument.getDocumentElement方法的具体用法?Java IMicroDocument.getDocumentElement怎么用?Java IMicroDocument.getDocumentElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.helger.xml.microdom.IMicroDocument
的用法示例。
在下文中一共展示了IMicroDocument.getDocumentElement方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSpecialXMLAttrs
import com.helger.xml.microdom.IMicroDocument; //导入方法依赖的package包/类
@Test
public void testSpecialXMLAttrs ()
{
final String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<root xml:lang=\"en\" xml:space=\"preserve\" xml:base=\"baseuri\" xml:id=\"4711\">" +
"Bla" +
"</root>";
final IMicroDocument aDoc = MicroReader.readMicroXML (s);
assertNotNull (aDoc);
final IMicroElement eRoot = aDoc.getDocumentElement ();
assertEquals ("en", eRoot.getAttributeValue (XMLConstants.XML_NS_URI, "lang"));
assertNull (eRoot.getAttributeValue ("lang"));
assertEquals ("preserve", eRoot.getAttributeValue (XMLConstants.XML_NS_URI, "space"));
assertEquals ("baseuri", eRoot.getAttributeValue (XMLConstants.XML_NS_URI, "base"));
assertEquals ("4711", eRoot.getAttributeValue (XMLConstants.XML_NS_URI, "id"));
// Ensure they are written as well
assertEquals (s, MicroWriter.getNodeAsString (aDoc, new XMLWriterSettings ().setIndent (EXMLSerializeIndent.NONE)));
}
示例2: testConvertToMicroElementWithNS
import com.helger.xml.microdom.IMicroDocument; //导入方法依赖的package包/类
@Test
public void testConvertToMicroElementWithNS () throws SAXException
{
final String sNS = "<root xmlns='blafoo'><ns2:element xmlns:ns2='ns2:uri' ns2:attr='value'>content</ns2:element></root>";
final Document aDoc = DOMReader.readXMLDOM (sNS);
assertNotNull (aDoc);
final IMicroDocument aMicroDoc = (IMicroDocument) MicroHelper.convertToMicroNode (aDoc);
assertNotNull (aMicroDoc);
final IMicroElement eRoot = aMicroDoc.getDocumentElement ();
assertNotNull (eRoot);
assertEquals ("blafoo", eRoot.getNamespaceURI ());
assertEquals ("root", eRoot.getLocalName ());
assertEquals ("root", eRoot.getTagName ());
assertEquals (0, eRoot.getAttributeCount ());
assertEquals (1, eRoot.getChildElementCount ());
final IMicroElement eElement = eRoot.getFirstChildElement ();
assertEquals ("ns2:uri", eElement.getNamespaceURI ());
assertEquals ("element", eElement.getLocalName ());
assertEquals ("element", eElement.getTagName ());
}
示例3: testAll
import com.helger.xml.microdom.IMicroDocument; //导入方法依赖的package包/类
@Test
public void testAll ()
{
final IMicroDocument aDoc = _buildTestDoc ();
final IMicroElement aDocElement = aDoc.getDocumentElement ();
ChildrenProviderElementWithName x = new ChildrenProviderElementWithName ("any");
assertTrue (x.hasChildren (aDocElement));
assertEquals (2, x.getChildCount (aDocElement));
assertEquals (2, x.getAllChildren (aDocElement).size ());
x = new ChildrenProviderElementWithName ("namespace", "any");
assertTrue (x.hasChildren (aDocElement));
assertEquals (1, x.getChildCount (aDocElement));
assertEquals (1, x.getAllChildren (aDocElement).size ());
try
{
new ChildrenProviderElementWithName ("");
fail ();
}
catch (final IllegalArgumentException ex)
{}
}
示例4: modifyWriteData
import com.helger.xml.microdom.IMicroDocument; //导入方法依赖的package包/类
/**
* Modify the created document by e.g. adding some comment or digital
* signature or whatsoever.
*
* @param aDoc
* The created non-<code>null</code> document.
*/
@OverrideOnDemand
@MustBeLocked (ELockType.WRITE)
protected void modifyWriteData (@Nonnull final IMicroDocument aDoc)
{
final IMicroComment aComment = new MicroComment ("This file was generated automatically - do NOT modify!\n" +
"Written at " +
PDTToString.getAsString (ZonedDateTime.now (Clock.systemUTC ()),
Locale.US));
final IMicroElement eRoot = aDoc.getDocumentElement ();
// Add a small comment
if (eRoot != null)
aDoc.insertBefore (aComment, eRoot);
else
aDoc.appendChild (aComment);
}
示例5: readSchema
import com.helger.xml.microdom.IMicroDocument; //导入方法依赖的package包/类
/**
* Read the schema from the resource supplied in the constructor. First all
* includes are resolved and than {@link #readSchemaFromXML(IMicroElement)} is
* called.
*
* @return The read {@link PSSchema}.
* @throws SchematronReadException
* If reading fails
*/
@Nonnull
public PSSchema readSchema () throws SchematronReadException
{
// Resolve all includes as the first action
final SAXReaderSettings aSettings = new SAXReaderSettings ().setEntityResolver (m_aEntityResolver);
final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes (m_aResource,
aSettings,
m_aErrorHandler);
if (aDoc == null || aDoc.getDocumentElement () == null)
throw new SchematronReadException (m_aResource,
"Failed to resolve includes in Schematron resource " + m_aResource);
if (SchematronDebug.isShowResolvedSourceSchematron ())
s_aLogger.info ("Resolved source Schematron:\n" + MicroWriter.getNodeAsString (aDoc));
return readSchemaFromXML (aDoc.getDocumentElement ());
}
示例6: getAsMicroElement
import com.helger.xml.microdom.IMicroDocument; //导入方法依赖的package包/类
/**
* Convert the passed object to a new micro document and return only the root
* element (write).
*
* @param aObject
* The object to be converted. May not be <code>null</code>.
* @return <code>null</code> if converting the document failed.
*/
@Nullable
default IMicroElement getAsMicroElement (@Nonnull final JAXBTYPE aObject)
{
final IMicroDocument aDoc = getAsMicroDocument (aObject);
if (aDoc == null)
return null;
final IMicroElement ret = aDoc.getDocumentElement ();
// Important to detach from document - otherwise the element cannot be
// re-added somewhere else
ret.detachFromParent ();
return ret;
}
示例7: getDocumentRootElementTagName
import com.helger.xml.microdom.IMicroDocument; //导入方法依赖的package包/类
/**
* Get the tag name of the passed documents root element.
*
* @param aDoc
* The document to be evaluated. May be <code>null</code>.
* @return <code>null</code> if the passed document was <code>null</code> or
* if no document element is present. The tag name otherwise.
*/
@Nullable
public static String getDocumentRootElementTagName (@Nullable final IMicroDocument aDoc)
{
if (aDoc != null)
{
final IMicroElement eRoot = aDoc.getDocumentElement ();
if (eRoot != null)
return eRoot.getTagName ();
}
return null;
}
示例8: convertWALStringToNative
import com.helger.xml.microdom.IMicroDocument; //导入方法依赖的package包/类
/**
* This method is used upon recovery to convert a stored object to its native
* representation. If you overwrite this method, you should consider
* overriding {@link #convertNativeToWALString(Serializable)} as well.
*
* @param sElement
* The string representation to be converted. Never <code>null</code>.
* @return The native representation of the object. If the return value is
* <code>null</code>, the recovery will fail with an exception!
*/
@Nullable
@OverrideOnDemand
@IsLocked (ELockType.WRITE)
protected DATATYPE convertWALStringToNative (@Nonnull final String sElement)
{
final IMicroDocument aDoc = MicroReader.readMicroXML (sElement);
if (aDoc == null || aDoc.getDocumentElement () == null)
return null;
return MicroTypeConverter.convertToNative (aDoc.getDocumentElement (), m_aDataTypeClass);
}
示例9: _readFromFile
import com.helger.xml.microdom.IMicroDocument; //导入方法依赖的package包/类
private void _readFromFile (@Nonnull final IReadableResource aRes)
{
final IMicroDocument aDoc = MicroReader.readMicroXML (aRes);
if (aDoc == null)
throw new IllegalArgumentException ("Failed to read " + aRes + " as XML document!");
final IMicroElement eRoot = aDoc.getDocumentElement ();
// Read all sectors
for (final IMicroElement eSector : eRoot.getFirstChildElement ("sectors").getAllChildElements ("sector"))
{
final int nGroupNum = StringParser.parseInt (eSector.getAttributeValue ("groupnum"), CGlobal.ILLEGAL_UINT);
final IMultilingualText aName = MicroTypeConverter.convertToNative (eSector.getFirstChildElement ("name"),
ReadOnlyMultilingualText.class);
final UnitSector aSector = new UnitSector (nGroupNum, aName);
final Integer aKey = aSector.getIDObj ();
if (m_aSectors.containsKey (aKey))
throw new IllegalStateException ("A unit sector with group number " +
aSector.getID () +
" is already contained!");
m_aSectors.put (aKey, aSector);
}
// Read all item
for (final IMicroElement eItem : eRoot.getFirstChildElement ("body").getAllChildElements ("item"))
{
// TODO
eItem.getAttributeValue ("id");
}
}
示例10: _readIBANDataFromXML
import com.helger.xml.microdom.IMicroDocument; //导入方法依赖的package包/类
/**
* Read all IBAN country data from a file.
*/
private static void _readIBANDataFromXML ()
{
final IMicroDocument aDoc = MicroReader.readMicroXML (new ClassPathResource ("codelists/iban-country-data.xml"));
if (aDoc == null)
throw new InitializationException ("Failed to read IBAN country data [1]");
if (aDoc.getDocumentElement () == null)
throw new InitializationException ("Failed to read IBAN country data [2]");
final DateTimeFormatter aDTPattern = DateTimeFormatter.ISO_DATE;
for (final IMicroElement eCountry : aDoc.getDocumentElement ().getAllChildElements (ELEMENT_COUNTRY))
{
// get descriptive string
final String sDesc = eCountry.getTextContent ();
final String sCountryCode = sDesc.substring (0, 2);
if (CountryCache.getInstance ().getCountry (sCountryCode) == null)
s_aLogger.warn ("IBAN country data: no such country code '" + sCountryCode + "' - be careful");
LocalDate aValidFrom = null;
if (eCountry.hasAttribute (ATTR_VALIDFROM))
{
// Constant format, conforming to XML date
aValidFrom = PDTFromString.getLocalDateFromString (eCountry.getAttributeValue (ATTR_VALIDFROM), aDTPattern);
}
LocalDate aValidTo = null;
if (eCountry.hasAttribute (ATTR_VALIDUNTIL))
{
// Constant format, conforming to XML date
aValidTo = PDTFromString.getLocalDateFromString (eCountry.getAttributeValue (ATTR_VALIDUNTIL), aDTPattern);
}
final String sLayout = eCountry.getAttributeValue (ATTR_LAYOUT);
final String sCheckDigits = eCountry.getAttributeValue (ATTR_CHECKDIGITS);
// get expected length
final String sLen = eCountry.getAttributeValue (ATTR_LEN);
final int nExpectedLength = StringParser.parseInt (sLen, CGlobal.ILLEGAL_UINT);
if (nExpectedLength == CGlobal.ILLEGAL_UINT)
throw new InitializationException ("Failed to convert length '" + sLen + "' to int!");
if (s_aIBANData.containsKey (sCountryCode))
throw new IllegalArgumentException ("Country " + sCountryCode + " is already contained!");
s_aIBANData.put (sCountryCode,
IBANCountryData.createFromString (sCountryCode,
nExpectedLength,
sLayout,
sCheckDigits,
aValidFrom,
aValidTo,
sDesc));
}
}