Class XmlFile
- java.lang.Object
-
- org.sonarsource.analyzer.commons.xml.XmlFile
-
public class XmlFile extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classXmlFile.Location
-
Method Summary
-
-
-
Method Detail
-
create
public static XmlFile create(org.sonar.api.batch.fs.InputFile inputFile) throws IOException
- Throws:
IOException
-
getInputFile
@Nullable public org.sonar.api.batch.fs.InputFile getInputFile()
- Returns:
- null when created based on string
-
getContents
public String getContents()
-
getCharset
public Charset getCharset()
-
getDocument
public Document getDocument()
- Returns:
- document with namespace information
-
getNamespaceAwareDocument
public Document getNamespaceAwareDocument()
-
getNamespaceUnawareDocument
public Document getNamespaceUnawareDocument()
-
getPrologElement
public Optional<PrologElement> getPrologElement()
-
startLocation
public static XmlTextRange startLocation(CDATASection node)
-
endLocation
public static XmlTextRange endLocation(CDATASection node)
-
startLocation
public static XmlTextRange startLocation(Element node)
-
endLocation
public static XmlTextRange endLocation(Element node)
-
nameLocation
public static XmlTextRange nameLocation(Element node)
-
attributeNameLocation
public static XmlTextRange attributeNameLocation(Attr node)
-
attributeValueLocation
public static XmlTextRange attributeValueLocation(Attr node)
-
nodeLocation
public static XmlTextRange nodeLocation(Node node)
-
getRange
public static Optional<XmlTextRange> getRange(Node node, XmlFile.Location location)
-
children
public static List<Node> children(Node node)
Get all the children of a node, as a proper java list.- Parameters:
node- the node to get children from- Returns:
- a list of nodes, possibly empty.
-
asList
public static List<Node> asList(@Nullable NodeList nodeList)
Transform a NodeList (from DOM interface) into a java List- Parameters:
nodeList- the nodeList to be transformed into a List, possibly null- Returns:
- The equivalent java list. Note that a null NodeList will produce an empty list.
-
nodeAttribute
@CheckForNull public static Node nodeAttribute(Node node, String attribute)
Try to retrieve the attribute node corresponding to an attribute name in a given node.- Parameters:
node- The node to query for an attributeattribute- The name of the attribute to search for- Returns:
- The corresponding attribute node, if the attribute can be found, or null if not found.
-
-