xml.Marshal creating too many tagsWhat is JSONP, and why was it created?Creating a JSON response using Django and PythonHow do I comment out a block of tags in XML?What are the use(s) for tags in Go?Go: Am I creating too many values?How to define multiple name tags in a structXML and JSON tags for a Golang struct?golang too many arguments to returnToo many arguments to return error“too many open files” with os.Create

How do I automatically add linebreaks "\" to the end of each row of a tabular environment?

Why has Speaker Pelosi been so hesitant to impeach President Trump?

Why do Russians sometimes spell "жирный" (fatty) as "жырный"?

IEEE 754 square root with Newton-Raphson

Is there a pattern for handling conflicting function parameters?

GPLv3 forces us to make code available, but to who?

Is there an in-universe explanation of how Frodo's arrival in Valinor was recorded in the Red Book?

How do we know neutrons have no charge?

Top off gas with old oil, is that bad?

Why does it seem the best way to make a living is to invest in real estate?

Why aren't faces sharp in my f/1.8 portraits even though I'm carefully using center-point autofocus?

Why isn't there armor to protect from spells in the Potterverse?

Beyond Futuristic Technology for an Alien Warship?

Numerical bases and prime number theory

Verb ending in -ん with positive meaning?

My machine, client installed VPN,

How deep is the liquid in a half-full hemisphere?

Why is the population of post-Soviet states declining?

Can I pay some of the cost of an activated ability lots of times to get more out of the effect?

Why would an airline put 15 passengers at once on standby?

Incomplete iffalse: How to shift a scope in polar coordinate?

Can an energy drink or chocolate before an exam be useful ? What sort of other edible goods be helpful?

Impossible violin chord, how to fix this?

Phonetic distortion when words are borrowed among languages



xml.Marshal creating too many tags


What is JSONP, and why was it created?Creating a JSON response using Django and PythonHow do I comment out a block of tags in XML?What are the use(s) for tags in Go?Go: Am I creating too many values?How to define multiple name tags in a structXML and JSON tags for a Golang struct?golang too many arguments to returnToo many arguments to return error“too many open files” with os.Create






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Parsing XML to JSON, then back to XML. I've mapped the <directory> XML tag to be ignored, but when xml.Marshal runs, I get:



<Directory><directory></directory>**MY DATA**</Directory>


I'd like the output XML to be:



<directory>**MY DATA**</directory>


The output is also only partial data from the input file; the last <fn>,<ct>,<ln> tags. This is true for either JSON or XML in their respective name conversions.



My golang:



package main

import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"log"
"os"
)

type Directory struct
XMLtag xml.Name `xml:"directory" json:"-"` //Locate XML <directory> tag
ContactList []ItemList `xml:"item_list" json:"directory"` //Locate XML <item_list> tag & call it "directory" in JSON


type ItemList struct
LocalContact *LocalContact `xml:"item" json:"contact"` //Locate XML <item> tag & call it "contact" in JSON


type LocalContact struct
Name string `xml:"fn" json:"name"` //Locate XML <fn> tag & call it "name" in JSON
Extension string `xml:"ct" json:"extension"` //Locate XML <ct> tag & call it "extension" in JSON
Long string `xml:"ln" json"ln"` //Locate XML <ln> tag


var (
localfile string = os.Getenv("USERPROFILE") + "\tmp-config.cfg"
)

func main()
f, err := ioutil.ReadFile(localfile)
if err != nil
log.Fatal(err)


//Read XML into struct
var directory Directory
xml.Unmarshal([]byte(f), &directory)
//Marshal XML to JSON
jsonData, _ := json.Marshal(directory)
fmt.Println(string(jsonData))

//Marshal JSON to XML
directory = Directory
json.Unmarshal([]byte(jsonData), &directory)
xmlData, _ := xml.Marshal(directory)
fmt.Println(string(xmlData))




My input file:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- $RCSfile: 000000000000-directory~.xml,v $ $Revision: 1.3 $ -->
<directory>
<item_list>
<item>
<ln> 1002 Shelly </ln>
<fn> Shelly </fn>
<ct> 1002 </ct>
</item>
<item>
<ln> 1003 Chris </ln>
<fn> Chris </fn>
<ct> 1003 </ct>
</item>
<item>
<ln> 1004 Extra </ln>
<fn> Extra </fn>
<ct> 1004 </ct>
</item>
<item>
<ln> 1005 Ray </ln>
<fn> Ray </fn>
<ct> 1005 </ct>
</item>
<item>
<ln> 1006 Kitchen </ln>
<fn> Kitchen </fn>
<ct> 1006 </ct>
</item>
<item>
<ln> 1007 Scott </ln>
<fn> Scott </fn>
<ct> 1007 </ct>
</item>
<item>
<ln> 1008 Heath </ln>
<fn> Heath </fn>
<ct> 1008 </ct>
</item>
<item>
<ln> 1009 Andy </ln>
<fn> Andy </fn>
<ct> 1009 </ct>
</item>
<item>
<ln> 1010 John </ln>
<fn> John </fn>
<ct> 1010 </ct>
</item>
</item_list>
</directory>









share|improve this question



















  • 1





    Try changing XMLtag to XMLName.

    – mkopriva
    Mar 28 at 20:24











  • play.golang.org/p/Sgx3hqEIwmS

    – mkopriva
    Mar 28 at 20:31











  • @mkopriva this should be the answer.

    – Vadim Ashikhman
    Mar 28 at 20:36


















0















Parsing XML to JSON, then back to XML. I've mapped the <directory> XML tag to be ignored, but when xml.Marshal runs, I get:



<Directory><directory></directory>**MY DATA**</Directory>


I'd like the output XML to be:



<directory>**MY DATA**</directory>


The output is also only partial data from the input file; the last <fn>,<ct>,<ln> tags. This is true for either JSON or XML in their respective name conversions.



My golang:



package main

import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"log"
"os"
)

type Directory struct
XMLtag xml.Name `xml:"directory" json:"-"` //Locate XML <directory> tag
ContactList []ItemList `xml:"item_list" json:"directory"` //Locate XML <item_list> tag & call it "directory" in JSON


type ItemList struct
LocalContact *LocalContact `xml:"item" json:"contact"` //Locate XML <item> tag & call it "contact" in JSON


type LocalContact struct
Name string `xml:"fn" json:"name"` //Locate XML <fn> tag & call it "name" in JSON
Extension string `xml:"ct" json:"extension"` //Locate XML <ct> tag & call it "extension" in JSON
Long string `xml:"ln" json"ln"` //Locate XML <ln> tag


var (
localfile string = os.Getenv("USERPROFILE") + "\tmp-config.cfg"
)

func main()
f, err := ioutil.ReadFile(localfile)
if err != nil
log.Fatal(err)


//Read XML into struct
var directory Directory
xml.Unmarshal([]byte(f), &directory)
//Marshal XML to JSON
jsonData, _ := json.Marshal(directory)
fmt.Println(string(jsonData))

//Marshal JSON to XML
directory = Directory
json.Unmarshal([]byte(jsonData), &directory)
xmlData, _ := xml.Marshal(directory)
fmt.Println(string(xmlData))




My input file:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- $RCSfile: 000000000000-directory~.xml,v $ $Revision: 1.3 $ -->
<directory>
<item_list>
<item>
<ln> 1002 Shelly </ln>
<fn> Shelly </fn>
<ct> 1002 </ct>
</item>
<item>
<ln> 1003 Chris </ln>
<fn> Chris </fn>
<ct> 1003 </ct>
</item>
<item>
<ln> 1004 Extra </ln>
<fn> Extra </fn>
<ct> 1004 </ct>
</item>
<item>
<ln> 1005 Ray </ln>
<fn> Ray </fn>
<ct> 1005 </ct>
</item>
<item>
<ln> 1006 Kitchen </ln>
<fn> Kitchen </fn>
<ct> 1006 </ct>
</item>
<item>
<ln> 1007 Scott </ln>
<fn> Scott </fn>
<ct> 1007 </ct>
</item>
<item>
<ln> 1008 Heath </ln>
<fn> Heath </fn>
<ct> 1008 </ct>
</item>
<item>
<ln> 1009 Andy </ln>
<fn> Andy </fn>
<ct> 1009 </ct>
</item>
<item>
<ln> 1010 John </ln>
<fn> John </fn>
<ct> 1010 </ct>
</item>
</item_list>
</directory>









share|improve this question



















  • 1





    Try changing XMLtag to XMLName.

    – mkopriva
    Mar 28 at 20:24











  • play.golang.org/p/Sgx3hqEIwmS

    – mkopriva
    Mar 28 at 20:31











  • @mkopriva this should be the answer.

    – Vadim Ashikhman
    Mar 28 at 20:36














0












0








0








Parsing XML to JSON, then back to XML. I've mapped the <directory> XML tag to be ignored, but when xml.Marshal runs, I get:



<Directory><directory></directory>**MY DATA**</Directory>


I'd like the output XML to be:



<directory>**MY DATA**</directory>


The output is also only partial data from the input file; the last <fn>,<ct>,<ln> tags. This is true for either JSON or XML in their respective name conversions.



My golang:



package main

import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"log"
"os"
)

type Directory struct
XMLtag xml.Name `xml:"directory" json:"-"` //Locate XML <directory> tag
ContactList []ItemList `xml:"item_list" json:"directory"` //Locate XML <item_list> tag & call it "directory" in JSON


type ItemList struct
LocalContact *LocalContact `xml:"item" json:"contact"` //Locate XML <item> tag & call it "contact" in JSON


type LocalContact struct
Name string `xml:"fn" json:"name"` //Locate XML <fn> tag & call it "name" in JSON
Extension string `xml:"ct" json:"extension"` //Locate XML <ct> tag & call it "extension" in JSON
Long string `xml:"ln" json"ln"` //Locate XML <ln> tag


var (
localfile string = os.Getenv("USERPROFILE") + "\tmp-config.cfg"
)

func main()
f, err := ioutil.ReadFile(localfile)
if err != nil
log.Fatal(err)


//Read XML into struct
var directory Directory
xml.Unmarshal([]byte(f), &directory)
//Marshal XML to JSON
jsonData, _ := json.Marshal(directory)
fmt.Println(string(jsonData))

//Marshal JSON to XML
directory = Directory
json.Unmarshal([]byte(jsonData), &directory)
xmlData, _ := xml.Marshal(directory)
fmt.Println(string(xmlData))




My input file:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- $RCSfile: 000000000000-directory~.xml,v $ $Revision: 1.3 $ -->
<directory>
<item_list>
<item>
<ln> 1002 Shelly </ln>
<fn> Shelly </fn>
<ct> 1002 </ct>
</item>
<item>
<ln> 1003 Chris </ln>
<fn> Chris </fn>
<ct> 1003 </ct>
</item>
<item>
<ln> 1004 Extra </ln>
<fn> Extra </fn>
<ct> 1004 </ct>
</item>
<item>
<ln> 1005 Ray </ln>
<fn> Ray </fn>
<ct> 1005 </ct>
</item>
<item>
<ln> 1006 Kitchen </ln>
<fn> Kitchen </fn>
<ct> 1006 </ct>
</item>
<item>
<ln> 1007 Scott </ln>
<fn> Scott </fn>
<ct> 1007 </ct>
</item>
<item>
<ln> 1008 Heath </ln>
<fn> Heath </fn>
<ct> 1008 </ct>
</item>
<item>
<ln> 1009 Andy </ln>
<fn> Andy </fn>
<ct> 1009 </ct>
</item>
<item>
<ln> 1010 John </ln>
<fn> John </fn>
<ct> 1010 </ct>
</item>
</item_list>
</directory>









share|improve this question














Parsing XML to JSON, then back to XML. I've mapped the <directory> XML tag to be ignored, but when xml.Marshal runs, I get:



<Directory><directory></directory>**MY DATA**</Directory>


I'd like the output XML to be:



<directory>**MY DATA**</directory>


The output is also only partial data from the input file; the last <fn>,<ct>,<ln> tags. This is true for either JSON or XML in their respective name conversions.



My golang:



package main

import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"log"
"os"
)

type Directory struct
XMLtag xml.Name `xml:"directory" json:"-"` //Locate XML <directory> tag
ContactList []ItemList `xml:"item_list" json:"directory"` //Locate XML <item_list> tag & call it "directory" in JSON


type ItemList struct
LocalContact *LocalContact `xml:"item" json:"contact"` //Locate XML <item> tag & call it "contact" in JSON


type LocalContact struct
Name string `xml:"fn" json:"name"` //Locate XML <fn> tag & call it "name" in JSON
Extension string `xml:"ct" json:"extension"` //Locate XML <ct> tag & call it "extension" in JSON
Long string `xml:"ln" json"ln"` //Locate XML <ln> tag


var (
localfile string = os.Getenv("USERPROFILE") + "\tmp-config.cfg"
)

func main()
f, err := ioutil.ReadFile(localfile)
if err != nil
log.Fatal(err)


//Read XML into struct
var directory Directory
xml.Unmarshal([]byte(f), &directory)
//Marshal XML to JSON
jsonData, _ := json.Marshal(directory)
fmt.Println(string(jsonData))

//Marshal JSON to XML
directory = Directory
json.Unmarshal([]byte(jsonData), &directory)
xmlData, _ := xml.Marshal(directory)
fmt.Println(string(xmlData))




My input file:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- $RCSfile: 000000000000-directory~.xml,v $ $Revision: 1.3 $ -->
<directory>
<item_list>
<item>
<ln> 1002 Shelly </ln>
<fn> Shelly </fn>
<ct> 1002 </ct>
</item>
<item>
<ln> 1003 Chris </ln>
<fn> Chris </fn>
<ct> 1003 </ct>
</item>
<item>
<ln> 1004 Extra </ln>
<fn> Extra </fn>
<ct> 1004 </ct>
</item>
<item>
<ln> 1005 Ray </ln>
<fn> Ray </fn>
<ct> 1005 </ct>
</item>
<item>
<ln> 1006 Kitchen </ln>
<fn> Kitchen </fn>
<ct> 1006 </ct>
</item>
<item>
<ln> 1007 Scott </ln>
<fn> Scott </fn>
<ct> 1007 </ct>
</item>
<item>
<ln> 1008 Heath </ln>
<fn> Heath </fn>
<ct> 1008 </ct>
</item>
<item>
<ln> 1009 Andy </ln>
<fn> Andy </fn>
<ct> 1009 </ct>
</item>
<item>
<ln> 1010 John </ln>
<fn> John </fn>
<ct> 1010 </ct>
</item>
</item_list>
</directory>






json xml go






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 20:18









user3051040user3051040

616 bronze badges




616 bronze badges










  • 1





    Try changing XMLtag to XMLName.

    – mkopriva
    Mar 28 at 20:24











  • play.golang.org/p/Sgx3hqEIwmS

    – mkopriva
    Mar 28 at 20:31











  • @mkopriva this should be the answer.

    – Vadim Ashikhman
    Mar 28 at 20:36













  • 1





    Try changing XMLtag to XMLName.

    – mkopriva
    Mar 28 at 20:24











  • play.golang.org/p/Sgx3hqEIwmS

    – mkopriva
    Mar 28 at 20:31











  • @mkopriva this should be the answer.

    – Vadim Ashikhman
    Mar 28 at 20:36








1




1





Try changing XMLtag to XMLName.

– mkopriva
Mar 28 at 20:24





Try changing XMLtag to XMLName.

– mkopriva
Mar 28 at 20:24













play.golang.org/p/Sgx3hqEIwmS

– mkopriva
Mar 28 at 20:31





play.golang.org/p/Sgx3hqEIwmS

– mkopriva
Mar 28 at 20:31













@mkopriva this should be the answer.

– Vadim Ashikhman
Mar 28 at 20:36






@mkopriva this should be the answer.

– Vadim Ashikhman
Mar 28 at 20:36













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/4.0/"u003ecc by-sa 4.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%2f55406215%2fxml-marshal-creating-too-many-tags%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
















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%2f55406215%2fxml-marshal-creating-too-many-tags%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권, 지리지 충청도 공주목 은진현