Para procurar o conteúdo indexado por regras de índice de procura XML,
defina seu texto de procura no formato elementName[attributeName='attributeValue'].
Inclua esse texto de procura como um campo de consulta de atributo em
RAMAssetQueryBuilder.
Os resultados até as correspondências XML específicas podem ser recuperados
pelo
ArtifactSearchResults resultante.
Exemplos de formatos para procura nos dados XML.
- Procura sem um elemento: attributeName='attributeValue'
- Procura por vários atributos definidos em um único elemento: elementName[attributeName1='attributeValue1'
attributeName2='attributeValue2]
- Procura por um caminho inteiro: elementPath1/elementPath2[attributeName='attributeValue']
- Procura por texto em um elemento: elementName[text()='textValue']
- O caractere curinga também pode ser utilizado ao procurar por documentos XML:
elementName[attributeName='attribute*']
//Perform search into XML indexed content
RAMAssetQueryBuilder query = new RAMAssetQueryBuilder(session);
//Make sure search within artifacts is on
query.setSearchModes(SearchQuery.SEARCH_WITHIN_ARTIFACTS_FLAG);
//XML index search text in the form elementName[attributeName='attributeValue']
String searchText = "wsdl:definitions[targetNamespace='*example*']";
query.addQueryField(query.QUERY_FIELD_ATTRIBUTE, searchText);
//Perform search
SearchResult result = session.getAssets(query);
//Get the list of asset matches
AssetSearchResult[] results = result.getAssetSearchResults();
for(int i = 0; i < results.length; i++){
//For an asset match get the list of artifact matches
ArtifactSearchResult[] artifactMatches = results[i].getMatchingArtifacts();
for(int j = 0; j < artifactMatches.length; j++){
//For an artifact match get the XML index matches
String[] xmlIndexMatches = artifactMatches[j].getMatches();
for(int k = 0; k < xmlIndexMatches.length; k++){
System.out.println("Match = " + xmlIndexMatches[k]);
}
}
}