XML parsing not happening with PrologReading a non UTF-8 text file in GoHow does one parse XML files?What characters do I need to escape in XML documents?How do I parse XML in Python?How do I comment out a block of tags in XML?What does <![CDATA[]]> in XML mean?How do you parse and process HTML/XML in PHP?Parsing invalid characters to XMLThe best node module for XML parsingGo String after variable declarationXML with text tags getting prematurely un-encoded when transformed in XSLT 1.0
Why does this syntax outputs an error under METAFUN/METAPOST?
Do we know the problems the University of Manchester's Transistor Computer was intended to solve?
Why do we need explainable AI?
Can there be plants on the dark side of a tidally locked world?
Importance of electrolytic capacitor size
Why do many programmers abstain from using global variables?
Sum of Infinite series with a Geometric series in multiply
How can I design a magically-induced coma?
Visiting girlfriend in the USA
How to disambiguate between various meditation practices?
What is the maximal acceptable delay between pilot's input and flight control surface actuation?
Meaning of "offen balkon machen"?
How to run a command 1 out of N times in Bash
Why do old games use flashing as means of showing damage?
Some questions about Lightning and Tor
Tiny image scraper for xkcd.com
Taking the first element in a list of associations
What is the significance of 104%?
Are there any writings by blinded and/or exiled Byzantine emperors?
How do we know if a dialogue sounds unnatural without asking for feedback?
Heuristic argument for the Riemann Hypothesis
Is torque as fundamental a concept as force?
How does Harry wear the invisibility cloak?
Do index funds really have double-digit percents annual return rates?
XML parsing not happening with Prolog
Reading a non UTF-8 text file in GoHow does one parse XML files?What characters do I need to escape in XML documents?How do I parse XML in Python?How do I comment out a block of tags in XML?What does <![CDATA[]]> in XML mean?How do you parse and process HTML/XML in PHP?Parsing invalid characters to XMLThe best node module for XML parsingGo String after variable declarationXML with text tags getting prematurely un-encoded when transformed in XSLT 1.0
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Recently I starting using Go. I am facing one problem while parsing XML.
Here is the issue:
I am successfully able to parse the following XML:
<Root>
<cookie name="e1">hsdhsdhs</cookie>
<cookie name="e2">sssss</cookie>
<cookie name="e3">null</cookie>
<info>
<name>sam</name>
</info>
</Root>
Here are the structs:
type Profile struct
RootElement xml.Name `xml:"Root"`
CookieList []Cookie `xml:"cookie"`
Info Information `xml:"info"`
type Cookie struct
Name string `xml:"name,attr"`
Value string `xml:",chardata"`
type Information struct
Name string `xml:"name"`
And the above struct is working fine.
profile := Profile
xml.Unmarshal([]byte(xmlString), &profile)
jsonData, _ := json.Marshal(profile)
fmt.Println(string(jsonData))
But as I keep prolog in XML:
<?xml version="1.0" encoding="EUC-JP"?>
<Root>
<cookie name="e1">hsdhsdhs</cookie>
<cookie name="e2">sssss</cookie>
<cookie name="e3">null</cookie>
<info>
<name>sam</name>
</info>
</Root>
then while printing, no data is displaying inside the JSON.
Not sure what is the issue here with Prolog.
xml go xml-parsing
|
show 2 more comments
Recently I starting using Go. I am facing one problem while parsing XML.
Here is the issue:
I am successfully able to parse the following XML:
<Root>
<cookie name="e1">hsdhsdhs</cookie>
<cookie name="e2">sssss</cookie>
<cookie name="e3">null</cookie>
<info>
<name>sam</name>
</info>
</Root>
Here are the structs:
type Profile struct
RootElement xml.Name `xml:"Root"`
CookieList []Cookie `xml:"cookie"`
Info Information `xml:"info"`
type Cookie struct
Name string `xml:"name,attr"`
Value string `xml:",chardata"`
type Information struct
Name string `xml:"name"`
And the above struct is working fine.
profile := Profile
xml.Unmarshal([]byte(xmlString), &profile)
jsonData, _ := json.Marshal(profile)
fmt.Println(string(jsonData))
But as I keep prolog in XML:
<?xml version="1.0" encoding="EUC-JP"?>
<Root>
<cookie name="e1">hsdhsdhs</cookie>
<cookie name="e2">sssss</cookie>
<cookie name="e3">null</cookie>
<info>
<name>sam</name>
</info>
</Root>
then while printing, no data is displaying inside the JSON.
Not sure what is the issue here with Prolog.
xml go xml-parsing
1
Change the encoding to utf-8..??
– devdotlog
Mar 28 at 2:37
1
Yes. Then it's working. But I need it for EUC-JP.
– nagendra547
Mar 28 at 2:38
1
Looks like the issue is with parsing using EUC-JP
– nagendra547
Mar 28 at 2:39
1
blog.tristanmedia.com/2014/10/…
– beiping96
Mar 28 at 3:51
1
@MaruthiAdithya Added information Struct
– nagendra547
Mar 28 at 4:00
|
show 2 more comments
Recently I starting using Go. I am facing one problem while parsing XML.
Here is the issue:
I am successfully able to parse the following XML:
<Root>
<cookie name="e1">hsdhsdhs</cookie>
<cookie name="e2">sssss</cookie>
<cookie name="e3">null</cookie>
<info>
<name>sam</name>
</info>
</Root>
Here are the structs:
type Profile struct
RootElement xml.Name `xml:"Root"`
CookieList []Cookie `xml:"cookie"`
Info Information `xml:"info"`
type Cookie struct
Name string `xml:"name,attr"`
Value string `xml:",chardata"`
type Information struct
Name string `xml:"name"`
And the above struct is working fine.
profile := Profile
xml.Unmarshal([]byte(xmlString), &profile)
jsonData, _ := json.Marshal(profile)
fmt.Println(string(jsonData))
But as I keep prolog in XML:
<?xml version="1.0" encoding="EUC-JP"?>
<Root>
<cookie name="e1">hsdhsdhs</cookie>
<cookie name="e2">sssss</cookie>
<cookie name="e3">null</cookie>
<info>
<name>sam</name>
</info>
</Root>
then while printing, no data is displaying inside the JSON.
Not sure what is the issue here with Prolog.
xml go xml-parsing
Recently I starting using Go. I am facing one problem while parsing XML.
Here is the issue:
I am successfully able to parse the following XML:
<Root>
<cookie name="e1">hsdhsdhs</cookie>
<cookie name="e2">sssss</cookie>
<cookie name="e3">null</cookie>
<info>
<name>sam</name>
</info>
</Root>
Here are the structs:
type Profile struct
RootElement xml.Name `xml:"Root"`
CookieList []Cookie `xml:"cookie"`
Info Information `xml:"info"`
type Cookie struct
Name string `xml:"name,attr"`
Value string `xml:",chardata"`
type Information struct
Name string `xml:"name"`
And the above struct is working fine.
profile := Profile
xml.Unmarshal([]byte(xmlString), &profile)
jsonData, _ := json.Marshal(profile)
fmt.Println(string(jsonData))
But as I keep prolog in XML:
<?xml version="1.0" encoding="EUC-JP"?>
<Root>
<cookie name="e1">hsdhsdhs</cookie>
<cookie name="e2">sssss</cookie>
<cookie name="e3">null</cookie>
<info>
<name>sam</name>
</info>
</Root>
then while printing, no data is displaying inside the JSON.
Not sure what is the issue here with Prolog.
xml go xml-parsing
xml go xml-parsing
edited Mar 28 at 4:00
nagendra547
asked Mar 28 at 2:05
nagendra547nagendra547
1,8858 silver badges26 bronze badges
1,8858 silver badges26 bronze badges
1
Change the encoding to utf-8..??
– devdotlog
Mar 28 at 2:37
1
Yes. Then it's working. But I need it for EUC-JP.
– nagendra547
Mar 28 at 2:38
1
Looks like the issue is with parsing using EUC-JP
– nagendra547
Mar 28 at 2:39
1
blog.tristanmedia.com/2014/10/…
– beiping96
Mar 28 at 3:51
1
@MaruthiAdithya Added information Struct
– nagendra547
Mar 28 at 4:00
|
show 2 more comments
1
Change the encoding to utf-8..??
– devdotlog
Mar 28 at 2:37
1
Yes. Then it's working. But I need it for EUC-JP.
– nagendra547
Mar 28 at 2:38
1
Looks like the issue is with parsing using EUC-JP
– nagendra547
Mar 28 at 2:39
1
blog.tristanmedia.com/2014/10/…
– beiping96
Mar 28 at 3:51
1
@MaruthiAdithya Added information Struct
– nagendra547
Mar 28 at 4:00
1
1
Change the encoding to utf-8..??
– devdotlog
Mar 28 at 2:37
Change the encoding to utf-8..??
– devdotlog
Mar 28 at 2:37
1
1
Yes. Then it's working. But I need it for EUC-JP.
– nagendra547
Mar 28 at 2:38
Yes. Then it's working. But I need it for EUC-JP.
– nagendra547
Mar 28 at 2:38
1
1
Looks like the issue is with parsing using EUC-JP
– nagendra547
Mar 28 at 2:39
Looks like the issue is with parsing using EUC-JP
– nagendra547
Mar 28 at 2:39
1
1
blog.tristanmedia.com/2014/10/…
– beiping96
Mar 28 at 3:51
blog.tristanmedia.com/2014/10/…
– beiping96
Mar 28 at 3:51
1
1
@MaruthiAdithya Added information Struct
– nagendra547
Mar 28 at 4:00
@MaruthiAdithya Added information Struct
– nagendra547
Mar 28 at 4:00
|
show 2 more comments
1 Answer
1
active
oldest
votes
Before parsing non-utf8 xml document you have to difine charset reader, thanks to golang.org/x/net/html/charset
all you need to do is just replace this string:
xml.Unmarshal([]byte(xmlString), &profile)
with:
decoder := xml.NewDecoder(bytes.NewBufferString(xmlString))
decoder.CharsetReader = charset.NewReaderLabel
err := decoder.Decode(&profile)
Thanks that solved the problem, but one issue I found, if there are some Japanese characters in name(e.g - サム ) under Information, then it's printing in weird fashion. It's printing binary characters I guess.
– nagendra547
Mar 29 at 2:46
@nagendra547 I just tested these symbols in xml and it outputs fine in json. By name you meanname
attribute of thecookie
tag?
– Vadim Ashikhman
Mar 29 at 11:09
name under the info TAG
– nagendra547
Mar 31 at 22:44
add a comment |
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%2f55389136%2fxml-parsing-not-happening-with-prolog%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Before parsing non-utf8 xml document you have to difine charset reader, thanks to golang.org/x/net/html/charset
all you need to do is just replace this string:
xml.Unmarshal([]byte(xmlString), &profile)
with:
decoder := xml.NewDecoder(bytes.NewBufferString(xmlString))
decoder.CharsetReader = charset.NewReaderLabel
err := decoder.Decode(&profile)
Thanks that solved the problem, but one issue I found, if there are some Japanese characters in name(e.g - サム ) under Information, then it's printing in weird fashion. It's printing binary characters I guess.
– nagendra547
Mar 29 at 2:46
@nagendra547 I just tested these symbols in xml and it outputs fine in json. By name you meanname
attribute of thecookie
tag?
– Vadim Ashikhman
Mar 29 at 11:09
name under the info TAG
– nagendra547
Mar 31 at 22:44
add a comment |
Before parsing non-utf8 xml document you have to difine charset reader, thanks to golang.org/x/net/html/charset
all you need to do is just replace this string:
xml.Unmarshal([]byte(xmlString), &profile)
with:
decoder := xml.NewDecoder(bytes.NewBufferString(xmlString))
decoder.CharsetReader = charset.NewReaderLabel
err := decoder.Decode(&profile)
Thanks that solved the problem, but one issue I found, if there are some Japanese characters in name(e.g - サム ) under Information, then it's printing in weird fashion. It's printing binary characters I guess.
– nagendra547
Mar 29 at 2:46
@nagendra547 I just tested these symbols in xml and it outputs fine in json. By name you meanname
attribute of thecookie
tag?
– Vadim Ashikhman
Mar 29 at 11:09
name under the info TAG
– nagendra547
Mar 31 at 22:44
add a comment |
Before parsing non-utf8 xml document you have to difine charset reader, thanks to golang.org/x/net/html/charset
all you need to do is just replace this string:
xml.Unmarshal([]byte(xmlString), &profile)
with:
decoder := xml.NewDecoder(bytes.NewBufferString(xmlString))
decoder.CharsetReader = charset.NewReaderLabel
err := decoder.Decode(&profile)
Before parsing non-utf8 xml document you have to difine charset reader, thanks to golang.org/x/net/html/charset
all you need to do is just replace this string:
xml.Unmarshal([]byte(xmlString), &profile)
with:
decoder := xml.NewDecoder(bytes.NewBufferString(xmlString))
decoder.CharsetReader = charset.NewReaderLabel
err := decoder.Decode(&profile)
answered Mar 28 at 16:20
Vadim AshikhmanVadim Ashikhman
6,9621 gold badge19 silver badges28 bronze badges
6,9621 gold badge19 silver badges28 bronze badges
Thanks that solved the problem, but one issue I found, if there are some Japanese characters in name(e.g - サム ) under Information, then it's printing in weird fashion. It's printing binary characters I guess.
– nagendra547
Mar 29 at 2:46
@nagendra547 I just tested these symbols in xml and it outputs fine in json. By name you meanname
attribute of thecookie
tag?
– Vadim Ashikhman
Mar 29 at 11:09
name under the info TAG
– nagendra547
Mar 31 at 22:44
add a comment |
Thanks that solved the problem, but one issue I found, if there are some Japanese characters in name(e.g - サム ) under Information, then it's printing in weird fashion. It's printing binary characters I guess.
– nagendra547
Mar 29 at 2:46
@nagendra547 I just tested these symbols in xml and it outputs fine in json. By name you meanname
attribute of thecookie
tag?
– Vadim Ashikhman
Mar 29 at 11:09
name under the info TAG
– nagendra547
Mar 31 at 22:44
Thanks that solved the problem, but one issue I found, if there are some Japanese characters in name(e.g - サム ) under Information, then it's printing in weird fashion. It's printing binary characters I guess.
– nagendra547
Mar 29 at 2:46
Thanks that solved the problem, but one issue I found, if there are some Japanese characters in name(e.g - サム ) under Information, then it's printing in weird fashion. It's printing binary characters I guess.
– nagendra547
Mar 29 at 2:46
@nagendra547 I just tested these symbols in xml and it outputs fine in json. By name you mean
name
attribute of the cookie
tag?– Vadim Ashikhman
Mar 29 at 11:09
@nagendra547 I just tested these symbols in xml and it outputs fine in json. By name you mean
name
attribute of the cookie
tag?– Vadim Ashikhman
Mar 29 at 11:09
name under the info TAG
– nagendra547
Mar 31 at 22:44
name under the info TAG
– nagendra547
Mar 31 at 22:44
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55389136%2fxml-parsing-not-happening-with-prolog%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
1
Change the encoding to utf-8..??
– devdotlog
Mar 28 at 2:37
1
Yes. Then it's working. But I need it for EUC-JP.
– nagendra547
Mar 28 at 2:38
1
Looks like the issue is with parsing using EUC-JP
– nagendra547
Mar 28 at 2:39
1
blog.tristanmedia.com/2014/10/…
– beiping96
Mar 28 at 3:51
1
@MaruthiAdithya Added information Struct
– nagendra547
Mar 28 at 4:00