You need to sign in to do that
Don't have an account?

How to read particular tag in every Node in XML string ?
here, i want to read DocID for each Allow node, i have written sample DOM to read the xml.
Is there any method to caluculate the size for nodes(here am having 3 Allow nodes,based on this want to read
each DocID, based on that want to perform some operation)
Can anyone help me in this.
String xml= ' <?xml version="1.0" encoding="utf-16"?>
<GETmethod xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Extend />
<Successful>true</Successful>
<CustAllowed>
<CustomerAllow>
<SampleData />
<CurrentDate>10/14/2015</currentDate>
<DocID>296</CID>
<DType>BP</CIDType>
<Allows>
<ALLOW>
<BID />
<sampleDesc>exist1</sampleDesc>
<sampleID>123456</sampleID>
<DocID>111</DocPID>
<State />
</ALLOW>
<ALLOW>
<BID />
<sampleDesc>exist1</sampleDesc>
<sampleID>123456</sampleID>
<DocID>222</DocPID>
<State />
</ALLOW>
<ALLOW>
<BID />
<sampleDesc>exist1</sampleDesc>
<sampleID>123454</sampleID>
<DocID>333</DocPID>
<State />
</ALLOW>
</Allows>
</CustAllow>
</CustAllowed>
</GetMethod>';
Dom.Document doc = new Dom.Document();
doc.load(xml);
//Retrieve the root element for this document.
Dom.XMLNode root = doc.getRootElement();
String strSuccessful= root.getChildElement('Successful', null).getText();
Dom.XMLNode ycharge=root.getChildElement('CustAllowed',null).getChildElement('CustomerAllow',null);
String strActivityDatey = ycharge.getChildElement('CurrentDate', null).getText();
String strCIDy = ycharge.getChildElement('DocID',null).getText();
String strCIDTypey = ycharge.getChildElement('DType',null).getText();
Dom.XMLNode ycharge1=ycharge.getChildElement('Allows',null);
for(Dom.XMLNode child: ycharge1.getChildElements())
{
Can anyone help here to read the each DocID in Allow nodes,here 3 nodes given in xml string
i want to write for loop to read the DocID,. can anyone help me in this
for(integer i=0;i<child.getAttributeCount();i++)
{
system.debug('DocID is +++++++ ' +child.gettext());
}
}
Is there any method to caluculate the size for nodes(here am having 3 Allow nodes,based on this want to read
each DocID, based on that want to perform some operation)
Can anyone help me in this.
String xml= ' <?xml version="1.0" encoding="utf-16"?>
<GETmethod xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Extend />
<Successful>true</Successful>
<CustAllowed>
<CustomerAllow>
<SampleData />
<CurrentDate>10/14/2015</currentDate>
<DocID>296</CID>
<DType>BP</CIDType>
<Allows>
<ALLOW>
<BID />
<sampleDesc>exist1</sampleDesc>
<sampleID>123456</sampleID>
<DocID>111</DocPID>
<State />
</ALLOW>
<ALLOW>
<BID />
<sampleDesc>exist1</sampleDesc>
<sampleID>123456</sampleID>
<DocID>222</DocPID>
<State />
</ALLOW>
<ALLOW>
<BID />
<sampleDesc>exist1</sampleDesc>
<sampleID>123454</sampleID>
<DocID>333</DocPID>
<State />
</ALLOW>
</Allows>
</CustAllow>
</CustAllowed>
</GetMethod>';
Dom.Document doc = new Dom.Document();
doc.load(xml);
//Retrieve the root element for this document.
Dom.XMLNode root = doc.getRootElement();
String strSuccessful= root.getChildElement('Successful', null).getText();
Dom.XMLNode ycharge=root.getChildElement('CustAllowed',null).getChildElement('CustomerAllow',null);
String strActivityDatey = ycharge.getChildElement('CurrentDate', null).getText();
String strCIDy = ycharge.getChildElement('DocID',null).getText();
String strCIDTypey = ycharge.getChildElement('DType',null).getText();
Dom.XMLNode ycharge1=ycharge.getChildElement('Allows',null);
for(Dom.XMLNode child: ycharge1.getChildElements())
{
Can anyone help here to read the each DocID in Allow nodes,here 3 nodes given in xml string
i want to write for loop to read the DocID,. can anyone help me in this
for(integer i=0;i<child.getAttributeCount();i++)
{
system.debug('DocID is +++++++ ' +child.gettext());
}
}
Also, your xml wasn't valid, so I cleaned it up. You may want to look at running it through xmllint [1]
[1] http://xmlsoft.org/xmllint.html