Hi, I am trying to figure out this loop logic.
I am pulling two attributes from a DB.
The Field Name and Field Value.
I want to create and XML String with the DB Field Name as an XML tag and place the DB Field Value inside the XML Tag.
I am able to get the field name and field value but I am having a hard time trying to work this logic.
This is what I want my end result to look like
<?xml version="1.0" encoding="UTF-8"?>
<xml xmlns:test="
http://localhost/test">
<test:XMLTest>
<test:XMLTagTest>
<test:Name>MyName</test:Na
me>
<test:Email>name@email.com
</test:Ema
il>
<test:Date>07/24/2008</tes
t:Date>
<test:Misc></test:Misc>
<test:Approve></test:Appro
ve>
</test:XMLTagTest>
</test:XMLTest>
</xml>
Here is the code I am using but I am having a hard time with the for loop for the values
Any suggestions. Thanks in advance.
String showNames[] = item.getAttrNames();// names of fields from DB
String showValues[] = item.getAttrValues();//val
ues in fields from DB
String value = null;
nodeHit = (ElementImpl)XMLHlper.crea
teAndAddte
stChildEle
ment(docXm
l, nodeHits, "XMLTagTest","");
for(int i = 0; i < showNames.length ; i++)
{
for(int j = 0; j < showValues.length ; j++) //trying to figure this part out
{
value = showValues[j];
System.out.println(value);
}
XMLHlper.createAndAddtestC
hildElemen
t(docXml, nodeHit, showNames[i], value);
xml = XMLHlper.getXmlString(docX
ml);
}
System.out.println(xml);
Here is what I get when I run the Code
These are the values that are pulled from the DB, which are correct
value = MyName
value = name@email.com
value = 07/24/2008
value =
value =
BUT the XML String comes up with blank values
<?xml version="1.0" encoding="UTF-8"?>
<xml xmlns:test="
http://localhost/test">
<test:XMLTest>
<test:XMLTagTest>
<test:Name></test:Name>
<test:Email></test:Email>
<test:Date></test:Date>
<test:Misc></test:Misc>
<test:Approve></test:Appro
ve>
</test:XMLTagTest>
</test:XMLTest>
</xml>