It's the first time I'm using stackoverflow and I don't speak English perfectly so be nice please.
I'm using Jaxb in append mode like that
for (Document330 document : documents){
JAXBContext jContext = JAXBContext.newInstance(Document330Xml.class);
Marshaller m = jContext.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(document, fos);
}
And I have an output file like that:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOCUMENT>
<MAILING>
<REF>M584</REF>
<LIBELLE>Mail Test 1</LIBELLE>
</MAILING>
</DOCUMENT>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOCUMENT>
<MAILING>
<REF>M585</REF>
<LIBELLE>Mail Test 2</LIBELLE>
</MAILING>
</DOCUMENT>
but I want something like that :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOCUMENTS>
<DOCUMENT>
<MAILING>
<REF>M584</REF>
<LIBELLE>Mail Test 1</LIBELLE>
</MAILING>
</DOCUMENT>
<DOCUMENT>
<MAILING>
<REF>M585</REF>
<LIBELLE>Mail Test 2</LIBELLE>
</MAILING>
</DOCUMENT>
</DOCUMENTS>
But it is possible that I have many XML. So I do not think the Unmarshaller is the best solution
Thanks for reading me
If I remind correctly, you need to create a Documents330Xml class, which can be marshalled (you can have a look at your Document330Xml class for reference). This class needs a list of Document330Xml as field.
If you then marshall the Documents330Xml class, you should get the desired XML.
Related
It is my first time for doing this.
Here is sample Input.xml file.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ns0:Accounts xmlns:ns0="urn:text.com:accounts">
<Recordset>
<Record>
<FIELD1>123</FIELD1>
<FIELD2/>
<FIELD3/>
<FIELD4>2020</FIELD4>
<FIELD5/>
</Record>
<Record>
<FIELD6>89</FIELD6>
<FIELD7>098</FIELD7>
<FIELD8/>
</Record>
</Recordset>
</ns0:Accounts>
I want to output like this
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ns0:Accounts xmlns:ns0="urn:text.com:accounts">
<Recordset>
<Record>
<FIELD1>123</FIELD1>
<FIELD2/>
<FIELD3/>
<FIELD4>2020</FIELD4>
<FIELD5/>
<FIELD6>89</FIELD6>
<FIELD7>098</FIELD7>
<FIELD8/>
</Record>
</Recordset>
</ns0:Accounts>
Here is java program:
NodeList child=doc.getElementsByTagName("Record");
for(int i=0;i<child.getLength();i++)
{
doc.renameNode(child.item(i),null,"");
}
To remove parent node like
Record
I've tried java DOM coding but didn't get.
Anyone help for this.
Thanks in advance
I need to count specifics occurences on XML ("true" or "false") and get the results in a table
I try using a tXMLMap but so far without success.
Any idea where I can lookinf for?
My XML:
<?xml version="1.0" encoding="UTF-8"?>
<customers>
<customer id="1">
<customerStatus vip="false" gold="false"/>
</customer>
<customer id="2">
<customerStatus vip="true" gold="false"/>
</customer>
<customer id="3">
<customerStatus vip="true" gold="true"/>
</customer>
</customers>
Wishes result:
vip
gold
2
1
Finnaly I succeed with:
tFileInputXml -> tXMLMap -> tAggregateRow -> tLogRow
How can I access the very first tag of a svg file (the tag < ?xml version...>).
e.g. :
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1000" height="1000" version="1.0">
.
.
.
</svg>
I would like to recover the very first node :
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
The conventionnal methods do not work, like :
doc.getFirstchild() or doc.getElementsByTagName(tagname)
Do you now a way to get it (I need to be able to access this element, not just put something before it) and to modify it at the same time ?
I created a java application that generates a whole bunch of simple XML files using the DocumentBuilder class. But now I need to go back and modify it so that all of the XML files also include this meta tag inserted before the root 'resultset' element:
<meta name="ZOOMPAGEBOOST" content="5">
So that the resulting files will look something like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="..\..\..\stylesheet\mysql-result.xsl"?>
<meta name="ZOOMPAGEBOOST" content="5">
<resultset>
<row>
...
</row>
</resultset>
Is this possible using the DocumentBuilder class? I figured this would have been a simple change, but I am having a difficult time finding the solution.
What you want to build is not well formed XML, DocumentBuilder won't let you build it because of that reason. Not to mention that the meta element you use in your example isn't valid XML either because it isn't closed; you have multiple problems here.
You have to have a single root element, the following is valid XML.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="..\..\..\stylesheet\mysql-result.xsl"?>
<resultset>
<meta name="ZOOMPAGEBOOST" content="5"/>
<row>
...
</row>
</resultset>
I have a xml file(ABC.xml) and i need to duplicate only the
<Transaction>...</Transaction>
multiple times(more than 100000 times) keeping the Header and Trailer intact creating NEW.xml whose final size may go upto 1GB. Also i have to increment the Uniqueid for every transaction in sequence.
As i m new to xml, i have been searching to this the best possible way, and im confused.
Can anyone please help me with the best way to do it(using DOM or SAX) and some piece of code.
Also can you please give me some links about it.
ABC.xml
========
<?xml version="1.0" encoding="UTF-8"?>
<Header><Datetime><date>20130209</date><Time>01:12</Time></Datetime></Header>
<Transaction>
<Uniqueid>1230001</Uniqueid>
<Affiliate>
<Name>abc</Name>
<Address>
<line1>aaaa</line1>
<line2>bbbb</line2>
<line3>cccc</line3>
</Address>
<Amount>123.00</Amount>
<Currency>USD</Currency>
<Purpose>
<line1>aaaa</line1>
<line2>bbbb</line2>
<line3>cccc</line3>
</Purpose>
</Affiliate>
</Transaction>
<Trailer><TotalTransactions>1</TotalTransactions><TotalAmount>123<TotalAmount> </Trailer>
NEW.xml
=======
<?xml version="1.0" encoding="UTF-8"?>
<Header><Datetime><date>20130209</date><Time>01:12</Time></Datetime></Header>
<Transaction>
<Uniqueid>1230001</Uniqueid>
<Affiliate>
<Name>abc</Name>
<Address>
<line1>aaaa</line1>
<line2>bbbb</line2>
<line3>cccc</line3>
</Address>
<Amount>123.00</Amount>
<Currency>USD</Currency>
<Purpose>
<line1>aaaa</line1>
<line2>bbbb</line2>
<line3>cccc</line3>
</Purpose>
</Affiliate>
</Transaction>
<Transaction>
<Uniqueid>1230002</Uniqueid>
<Affiliate>
<Name>abc</Name>
<Address>
<line1>aaaa</line1>
<line2>bbbb</line2>
<line3>cccc</line3>
</Address>
<Amount>123.00</Amount>
<Currency>USD</Currency>
<Purpose>
<line1>aaaa</line1>
<line2>bbbb</line2>
<line3>cccc</line3>
</Purpose>
</Affiliate>
</Transaction>
<Trailer><TotalTransactions>2</TotalTransactions><TotalAmount>246<TotalAmount></Trailer>
It would help if your source XML were well-formed - it needs an outer wrapper element.
There are a number of XQuery processors available in Java, for example Saxon. Just execute the query
<doc>{doc/Header, for $i in 1 to 100000 return doc/Transaction, doc/Footer}</doc>
on the supplied input document, assuming <doc> as the outer wrapper element.