I am trying to parse the XML and get to a node and delete is using the below code...
DocumentBuilderFactory domBuilderFactory = DocumentBuilderFactory.newInstance();
domBuilderFactory.setNamespaceAware(true);
Document document = domBuilderFactory.newDocumentBuilder().parse(new InputSource(new StringReader(XML)));
NodeList nodes = (NodeList) XPathFactory.newInstance().newXPath()
.compile("/TrustFrameworkPolicy/BuildModel/RestSchema/CustType[starts-with(@Id, 'regular.Command-Nest.type')]")
.evaluate(document, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
nodes.item(i).getParentNode().removeChild(nodes.item(i));
}
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(document), new StreamResult(System.out));
Below is the XML that I am parsing...but the problem is that I am not able to parse it because of the TrustFrameworkPolicy since it is long and has a lot of data...
<TrustFrameworkPolicy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.microsoft.com/online/cpim/schemas/2013/06" PolicySchemaVersion="0.3.0.0" TenantId="{Settings:Tenant}" PolicyId="B2C_1A_User_MigrationClients" PublicPolicyUri="http://{Settings:Tenant}/B2C_1A_User_MigrationClients" DeploymentMode="{Settings:DeploymentMode}" UserJourneyRecorderEndpoint="urn:journeyrecorder:applicationinsights">
<BuildModel>
<RestSchema>
<CustType Id="regular.type1">
<DataType>string</DataType>
</CustType>
<CustType Id="regular.type2">
<DataType>string</DataType>
</CustType>
<CustType Id="regular.Command-Nest.type1">
<DataType>string</DataType>
</CustType>
<CustType Id="regular.Command-Nest.type2">
<DataType>string</DataType>
</CustType>
<CustType Id="regular.type3">
<DataType>string</DataType>
</CustType>
<CustType Id="regular.Command-Nest.type4">
<DataType>string</DataType>
</CustType>
</RestSchema>
</BuildModel>
</TrustFrameworkPolicy>
BUT when I am testing by modifying the XML just to see if my java code is correct I am editing TrustFrameworkPolicy like this...IT IS WORKING FINE, I am able to parse and do my work
<TrustFrameworkPolicy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<BuildModel>
<RestSchema>
<CustType Id="regular.type1">
<DataType>string</DataType>
</CustType>
<CustType Id="regular.type2">
<DataType>string</DataType>
</CustType>
<CustType Id="regular.Command-Nest.type1">
<DataType>string</DataType>
</CustType>
<CustType Id="regular.Command-Nest.type2">
<DataType>string</DataType>
</CustType>
<CustType Id="regular.type3">
<DataType>string</DataType>
</CustType>
<CustType Id="regular.Command-Nest.type4">
<DataType>string</DataType>
</CustType>
</RestSchema>
</BuildModel>
</TrustFrameworkPolicy>
OUTPUT (with updated TrustFrameworkPolicy tag)
<TrustFrameworkPolicy xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<BasePolicy>
<TenantId>egenginfob2cint.onmicrosoft.com</TenantId>
<PolicyId>B2C_1A_User_TrustFrameworkExtensions_MultiTenant</PolicyId>
</BasePolicy>
<BuildingBlocks>
<ClaimsSchema>
<ClaimType Id="custom.rule1">
<DataType>string</DataType>
</ClaimType>
<ClaimType Id="custom.rule2">
<DataType>string</DataType>
</ClaimType>
</ClaimsSchema>
</BuildingBlocks>
</TrustFrameworkPolicy>
Can someone tell me what is happening and guide me how to get through this...or share a link that I can refer to.