Save XML to CSV using java Namespace prefix is undeclared
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am trying to save XML file to CSV with java, but I receive 'Namespace prefix 'lst' is undeclared' error message.
This is XSL file:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/listInvoice">
<!-- header -->
<xsl:text>nieco
</xsl:text>
<!-- data -->
<xsl:for-each select="lst:invoice/inv:invoiceHeader">
<!-- classroom data -->
<xsl:variable name="inv:invoiceHeader">
<xsl:value-of select="@inv:id" />
<xsl:text>,</xsl:text>
</xsl:variable>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
This is XML file:
<?xml version="1.0" encoding="UTF-8"?>
<listInvoice>
<lst:invoice>
<inv:invoiceHeader>
<inv:id>9136</inv:id>
<inv:invoiceType>issuedInvoice</inv:invoiceType>
<inv:number>
<typ:id>435</typ:id>
<typ:numberRequested>1710203</typ:numberRequested>
</inv:number>
</inv:invoiceHeader>
</lst:invoice>
</listInvoice>
java code:
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
class XMLtoCsVConversion2 {
public static void main(String args) throws Exception {
File stylesheet = new File("new.xsl");
File xmlSource = new File("test.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(xmlSource);
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = TransformerFactory.newInstance()
.newTransformer(stylesource);
Source source = new DOMSource(document);
Result outputTarget = new StreamResult(new File("xyz.csv"));
transformer.transform(source, outputTarget);
}
}
Could you please help where could be the problem?
Could be the reason be xml tag consist of 2 parts splitted by semicolon?
Thanks
java xml csv
add a comment |
I am trying to save XML file to CSV with java, but I receive 'Namespace prefix 'lst' is undeclared' error message.
This is XSL file:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/listInvoice">
<!-- header -->
<xsl:text>nieco
</xsl:text>
<!-- data -->
<xsl:for-each select="lst:invoice/inv:invoiceHeader">
<!-- classroom data -->
<xsl:variable name="inv:invoiceHeader">
<xsl:value-of select="@inv:id" />
<xsl:text>,</xsl:text>
</xsl:variable>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
This is XML file:
<?xml version="1.0" encoding="UTF-8"?>
<listInvoice>
<lst:invoice>
<inv:invoiceHeader>
<inv:id>9136</inv:id>
<inv:invoiceType>issuedInvoice</inv:invoiceType>
<inv:number>
<typ:id>435</typ:id>
<typ:numberRequested>1710203</typ:numberRequested>
</inv:number>
</inv:invoiceHeader>
</lst:invoice>
</listInvoice>
java code:
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
class XMLtoCsVConversion2 {
public static void main(String args) throws Exception {
File stylesheet = new File("new.xsl");
File xmlSource = new File("test.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(xmlSource);
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = TransformerFactory.newInstance()
.newTransformer(stylesource);
Source source = new DOMSource(document);
Result outputTarget = new StreamResult(new File("xyz.csv"));
transformer.transform(source, outputTarget);
}
}
Could you please help where could be the problem?
Could be the reason be xml tag consist of 2 parts splitted by semicolon?
Thanks
java xml csv
does this help? stackoverflow.com/questions/38700926/…
– Andrea
Nov 23 '18 at 16:57
Hello Andrea. I tried and no, it doesn`t work :(
– bennes
Nov 26 '18 at 9:16
doesxmllint
confirm it's valid?
– Thufir
Jan 10 at 19:57
add a comment |
I am trying to save XML file to CSV with java, but I receive 'Namespace prefix 'lst' is undeclared' error message.
This is XSL file:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/listInvoice">
<!-- header -->
<xsl:text>nieco
</xsl:text>
<!-- data -->
<xsl:for-each select="lst:invoice/inv:invoiceHeader">
<!-- classroom data -->
<xsl:variable name="inv:invoiceHeader">
<xsl:value-of select="@inv:id" />
<xsl:text>,</xsl:text>
</xsl:variable>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
This is XML file:
<?xml version="1.0" encoding="UTF-8"?>
<listInvoice>
<lst:invoice>
<inv:invoiceHeader>
<inv:id>9136</inv:id>
<inv:invoiceType>issuedInvoice</inv:invoiceType>
<inv:number>
<typ:id>435</typ:id>
<typ:numberRequested>1710203</typ:numberRequested>
</inv:number>
</inv:invoiceHeader>
</lst:invoice>
</listInvoice>
java code:
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
class XMLtoCsVConversion2 {
public static void main(String args) throws Exception {
File stylesheet = new File("new.xsl");
File xmlSource = new File("test.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(xmlSource);
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = TransformerFactory.newInstance()
.newTransformer(stylesource);
Source source = new DOMSource(document);
Result outputTarget = new StreamResult(new File("xyz.csv"));
transformer.transform(source, outputTarget);
}
}
Could you please help where could be the problem?
Could be the reason be xml tag consist of 2 parts splitted by semicolon?
Thanks
java xml csv
I am trying to save XML file to CSV with java, but I receive 'Namespace prefix 'lst' is undeclared' error message.
This is XSL file:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/listInvoice">
<!-- header -->
<xsl:text>nieco
</xsl:text>
<!-- data -->
<xsl:for-each select="lst:invoice/inv:invoiceHeader">
<!-- classroom data -->
<xsl:variable name="inv:invoiceHeader">
<xsl:value-of select="@inv:id" />
<xsl:text>,</xsl:text>
</xsl:variable>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
This is XML file:
<?xml version="1.0" encoding="UTF-8"?>
<listInvoice>
<lst:invoice>
<inv:invoiceHeader>
<inv:id>9136</inv:id>
<inv:invoiceType>issuedInvoice</inv:invoiceType>
<inv:number>
<typ:id>435</typ:id>
<typ:numberRequested>1710203</typ:numberRequested>
</inv:number>
</inv:invoiceHeader>
</lst:invoice>
</listInvoice>
java code:
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
class XMLtoCsVConversion2 {
public static void main(String args) throws Exception {
File stylesheet = new File("new.xsl");
File xmlSource = new File("test.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(xmlSource);
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = TransformerFactory.newInstance()
.newTransformer(stylesource);
Source source = new DOMSource(document);
Result outputTarget = new StreamResult(new File("xyz.csv"));
transformer.transform(source, outputTarget);
}
}
Could you please help where could be the problem?
Could be the reason be xml tag consist of 2 parts splitted by semicolon?
Thanks
java xml csv
java xml csv
asked Nov 23 '18 at 16:33
bennesbennes
2128
2128
does this help? stackoverflow.com/questions/38700926/…
– Andrea
Nov 23 '18 at 16:57
Hello Andrea. I tried and no, it doesn`t work :(
– bennes
Nov 26 '18 at 9:16
doesxmllint
confirm it's valid?
– Thufir
Jan 10 at 19:57
add a comment |
does this help? stackoverflow.com/questions/38700926/…
– Andrea
Nov 23 '18 at 16:57
Hello Andrea. I tried and no, it doesn`t work :(
– bennes
Nov 26 '18 at 9:16
doesxmllint
confirm it's valid?
– Thufir
Jan 10 at 19:57
does this help? stackoverflow.com/questions/38700926/…
– Andrea
Nov 23 '18 at 16:57
does this help? stackoverflow.com/questions/38700926/…
– Andrea
Nov 23 '18 at 16:57
Hello Andrea. I tried and no, it doesn`t work :(
– bennes
Nov 26 '18 at 9:16
Hello Andrea. I tried and no, it doesn`t work :(
– bennes
Nov 26 '18 at 9:16
does
xmllint
confirm it's valid?– Thufir
Jan 10 at 19:57
does
xmllint
confirm it's valid?– Thufir
Jan 10 at 19:57
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53450208%2fsave-xml-to-csv-using-java-namespace-prefix-is-undeclared%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53450208%2fsave-xml-to-csv-using-java-namespace-prefix-is-undeclared%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
does this help? stackoverflow.com/questions/38700926/…
– Andrea
Nov 23 '18 at 16:57
Hello Andrea. I tried and no, it doesn`t work :(
– bennes
Nov 26 '18 at 9:16
does
xmllint
confirm it's valid?– Thufir
Jan 10 at 19:57