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;








1















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.










share|improve this question





















  • 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















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.










share|improve this question





















  • 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








1








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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












1 Answer
1






active

oldest

votes


















2















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)





share|improve this answer

























  • 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












  • name under the info TAG

    – nagendra547
    Mar 31 at 22:44










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
);



);













draft saved

draft discarded


















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









2















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)





share|improve this answer

























  • 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












  • name under the info TAG

    – nagendra547
    Mar 31 at 22:44















2















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)





share|improve this answer

























  • 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












  • name under the info TAG

    – nagendra547
    Mar 31 at 22:44













2














2










2









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)





share|improve this answer













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)






share|improve this answer












share|improve this answer



share|improve this answer










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 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

















  • 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












  • 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








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.



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현