Below is the XML I have
<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>
</RestSchema>
</BuildModel>
</TrustFrameworkPolicy>
I have to add new nodes under "RestSchema"
This is how I want to create new
<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>
</RestSchema>
</BuildModel>
</TrustFrameworkPolicy>
How can I do it using XPATH. I have to create this type of structure in the EXISTING XML under.
I know how to track down to the tag I just need to know how I can create these in java using XPATH.
private static void addNewCustType(String updatedXMLPath) throws Exception {
System.out.println("Adding new claim types.");
Document document = getXmlAsDocument(updatedXMLPath);
for (int i = 0; i < newClaim.size() ; i++ ) {
// This is how I am traversing to the TAG where I need to add
String expression = "/*[local-name() = 'TrustFrameworkPolicy']/*[local-name() = 'BuildModel']/*[local-name() = 'RestSchema']";
// I need to understand how I can create a node under "above" path...
}
}
private static Document getXmlAsDocument(String fileName) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(fileName);
return doc;
}