C# - YAXLib: “No elements with this name found:”
I have two classes that are used for de/serializing an XML file.
XmlExampleBasicUnit.cs:
[YAXSerializeAs("Unit")]
public class XmlExampleBasicUnit
{
[YAXSerializeAs("StringVar")]
public String StringVar { get; set; }
[YAXSerializeAs("Int32Var")]
public Int32 Int32Var { get; set; }
[YAXSerializeAs("DoubleVar")]
public Double DoubleVar { get; set; }
[YAXSerializeAs("DateTimeVar")]
public String DateTimeVar { get; set; }
[YAXSerializeAs("CharVar")]
public String CharVar { get; set; }
}
XmlExampleCollectionOfUnits.cs:
[YAXSerializeAs("CollectionOfUnits")]
public class XmlExampleCollectionOfUnits
{
[YAXSerializeAs("Units")]
public List<XmlExampleBasicUnit> Units { get; set; }
public XmlExampleCollectionOfUnits(List<XmlExampleBasicUnit> units)
{
Units = units;
}
public XmlExampleCollectionOfUnits()
{
}
}
I'm trying to deserialize this file:
<?xml version="1.0" encoding="utf-8"?>
<CollectionOfUnits>
<Units>
<Unit>
<StringVar>TohleJeString</StringVar>
<Int32Var>24</Int32Var>
<DoubleVar>29.6</DoubleVar>
<DateTimeVar>17.11.1968</DateTimeVar>
<CharVar>c</CharVar>
</Unit>
<Unit>
<StringVar>TohleJeTakéString</StringVar>
<Int32Var>17</Int32Var>
<DoubleVar>5.9</DoubleVar>
<DateTimeVar>06.07.1415</DateTimeVar>
<CharVar>p</CharVar>
</Unit>
<Unit>
<StringVar>NoATohleTaké</StringVar>
<Int32Var>2</Int32Var>
<DoubleVar>78.5</DoubleVar>
<DateTimeVar>06.12.1774</DateTimeVar>
<CharVar>x</CharVar>
</Unit>
</Units>
It's all handled by this function:
public T Import<T>(String fileName) where T : class
{
YAXSerializer serializer = new YAXSerializer(typeof(T));
return (T)serializer.Deserialize(fileName);
}
When I run the code I get following error: No elements with this name found: './Units'.
As you can see there already is an element called Units
.
c# xml xml-serialization yaxlib
|
show 5 more comments
I have two classes that are used for de/serializing an XML file.
XmlExampleBasicUnit.cs:
[YAXSerializeAs("Unit")]
public class XmlExampleBasicUnit
{
[YAXSerializeAs("StringVar")]
public String StringVar { get; set; }
[YAXSerializeAs("Int32Var")]
public Int32 Int32Var { get; set; }
[YAXSerializeAs("DoubleVar")]
public Double DoubleVar { get; set; }
[YAXSerializeAs("DateTimeVar")]
public String DateTimeVar { get; set; }
[YAXSerializeAs("CharVar")]
public String CharVar { get; set; }
}
XmlExampleCollectionOfUnits.cs:
[YAXSerializeAs("CollectionOfUnits")]
public class XmlExampleCollectionOfUnits
{
[YAXSerializeAs("Units")]
public List<XmlExampleBasicUnit> Units { get; set; }
public XmlExampleCollectionOfUnits(List<XmlExampleBasicUnit> units)
{
Units = units;
}
public XmlExampleCollectionOfUnits()
{
}
}
I'm trying to deserialize this file:
<?xml version="1.0" encoding="utf-8"?>
<CollectionOfUnits>
<Units>
<Unit>
<StringVar>TohleJeString</StringVar>
<Int32Var>24</Int32Var>
<DoubleVar>29.6</DoubleVar>
<DateTimeVar>17.11.1968</DateTimeVar>
<CharVar>c</CharVar>
</Unit>
<Unit>
<StringVar>TohleJeTakéString</StringVar>
<Int32Var>17</Int32Var>
<DoubleVar>5.9</DoubleVar>
<DateTimeVar>06.07.1415</DateTimeVar>
<CharVar>p</CharVar>
</Unit>
<Unit>
<StringVar>NoATohleTaké</StringVar>
<Int32Var>2</Int32Var>
<DoubleVar>78.5</DoubleVar>
<DateTimeVar>06.12.1774</DateTimeVar>
<CharVar>x</CharVar>
</Unit>
</Units>
It's all handled by this function:
public T Import<T>(String fileName) where T : class
{
YAXSerializer serializer = new YAXSerializer(typeof(T));
return (T)serializer.Deserialize(fileName);
}
When I run the code I get following error: No elements with this name found: './Units'.
As you can see there already is an element called Units
.
c# xml xml-serialization yaxlib
1
it doesn't give me any error ! how did you callImport
function?
– er-sho
Nov 28 '18 at 10:38
1
Thank you! I have realized theImport()
function is reading incorrect values.
– Chyu
Nov 28 '18 at 10:58
you need to pass xml content toImport
function rather than passing path of xml file
– er-sho
Nov 28 '18 at 11:00
What if I want to use path of XML file?
– Chyu
Nov 28 '18 at 11:43
then you have to fetch content of xml in yourImport
function from path. let me add an solution for you
– er-sho
Nov 28 '18 at 11:51
|
show 5 more comments
I have two classes that are used for de/serializing an XML file.
XmlExampleBasicUnit.cs:
[YAXSerializeAs("Unit")]
public class XmlExampleBasicUnit
{
[YAXSerializeAs("StringVar")]
public String StringVar { get; set; }
[YAXSerializeAs("Int32Var")]
public Int32 Int32Var { get; set; }
[YAXSerializeAs("DoubleVar")]
public Double DoubleVar { get; set; }
[YAXSerializeAs("DateTimeVar")]
public String DateTimeVar { get; set; }
[YAXSerializeAs("CharVar")]
public String CharVar { get; set; }
}
XmlExampleCollectionOfUnits.cs:
[YAXSerializeAs("CollectionOfUnits")]
public class XmlExampleCollectionOfUnits
{
[YAXSerializeAs("Units")]
public List<XmlExampleBasicUnit> Units { get; set; }
public XmlExampleCollectionOfUnits(List<XmlExampleBasicUnit> units)
{
Units = units;
}
public XmlExampleCollectionOfUnits()
{
}
}
I'm trying to deserialize this file:
<?xml version="1.0" encoding="utf-8"?>
<CollectionOfUnits>
<Units>
<Unit>
<StringVar>TohleJeString</StringVar>
<Int32Var>24</Int32Var>
<DoubleVar>29.6</DoubleVar>
<DateTimeVar>17.11.1968</DateTimeVar>
<CharVar>c</CharVar>
</Unit>
<Unit>
<StringVar>TohleJeTakéString</StringVar>
<Int32Var>17</Int32Var>
<DoubleVar>5.9</DoubleVar>
<DateTimeVar>06.07.1415</DateTimeVar>
<CharVar>p</CharVar>
</Unit>
<Unit>
<StringVar>NoATohleTaké</StringVar>
<Int32Var>2</Int32Var>
<DoubleVar>78.5</DoubleVar>
<DateTimeVar>06.12.1774</DateTimeVar>
<CharVar>x</CharVar>
</Unit>
</Units>
It's all handled by this function:
public T Import<T>(String fileName) where T : class
{
YAXSerializer serializer = new YAXSerializer(typeof(T));
return (T)serializer.Deserialize(fileName);
}
When I run the code I get following error: No elements with this name found: './Units'.
As you can see there already is an element called Units
.
c# xml xml-serialization yaxlib
I have two classes that are used for de/serializing an XML file.
XmlExampleBasicUnit.cs:
[YAXSerializeAs("Unit")]
public class XmlExampleBasicUnit
{
[YAXSerializeAs("StringVar")]
public String StringVar { get; set; }
[YAXSerializeAs("Int32Var")]
public Int32 Int32Var { get; set; }
[YAXSerializeAs("DoubleVar")]
public Double DoubleVar { get; set; }
[YAXSerializeAs("DateTimeVar")]
public String DateTimeVar { get; set; }
[YAXSerializeAs("CharVar")]
public String CharVar { get; set; }
}
XmlExampleCollectionOfUnits.cs:
[YAXSerializeAs("CollectionOfUnits")]
public class XmlExampleCollectionOfUnits
{
[YAXSerializeAs("Units")]
public List<XmlExampleBasicUnit> Units { get; set; }
public XmlExampleCollectionOfUnits(List<XmlExampleBasicUnit> units)
{
Units = units;
}
public XmlExampleCollectionOfUnits()
{
}
}
I'm trying to deserialize this file:
<?xml version="1.0" encoding="utf-8"?>
<CollectionOfUnits>
<Units>
<Unit>
<StringVar>TohleJeString</StringVar>
<Int32Var>24</Int32Var>
<DoubleVar>29.6</DoubleVar>
<DateTimeVar>17.11.1968</DateTimeVar>
<CharVar>c</CharVar>
</Unit>
<Unit>
<StringVar>TohleJeTakéString</StringVar>
<Int32Var>17</Int32Var>
<DoubleVar>5.9</DoubleVar>
<DateTimeVar>06.07.1415</DateTimeVar>
<CharVar>p</CharVar>
</Unit>
<Unit>
<StringVar>NoATohleTaké</StringVar>
<Int32Var>2</Int32Var>
<DoubleVar>78.5</DoubleVar>
<DateTimeVar>06.12.1774</DateTimeVar>
<CharVar>x</CharVar>
</Unit>
</Units>
It's all handled by this function:
public T Import<T>(String fileName) where T : class
{
YAXSerializer serializer = new YAXSerializer(typeof(T));
return (T)serializer.Deserialize(fileName);
}
When I run the code I get following error: No elements with this name found: './Units'.
As you can see there already is an element called Units
.
c# xml xml-serialization yaxlib
c# xml xml-serialization yaxlib
asked Nov 28 '18 at 10:20
ChyuChyu
157317
157317
1
it doesn't give me any error ! how did you callImport
function?
– er-sho
Nov 28 '18 at 10:38
1
Thank you! I have realized theImport()
function is reading incorrect values.
– Chyu
Nov 28 '18 at 10:58
you need to pass xml content toImport
function rather than passing path of xml file
– er-sho
Nov 28 '18 at 11:00
What if I want to use path of XML file?
– Chyu
Nov 28 '18 at 11:43
then you have to fetch content of xml in yourImport
function from path. let me add an solution for you
– er-sho
Nov 28 '18 at 11:51
|
show 5 more comments
1
it doesn't give me any error ! how did you callImport
function?
– er-sho
Nov 28 '18 at 10:38
1
Thank you! I have realized theImport()
function is reading incorrect values.
– Chyu
Nov 28 '18 at 10:58
you need to pass xml content toImport
function rather than passing path of xml file
– er-sho
Nov 28 '18 at 11:00
What if I want to use path of XML file?
– Chyu
Nov 28 '18 at 11:43
then you have to fetch content of xml in yourImport
function from path. let me add an solution for you
– er-sho
Nov 28 '18 at 11:51
1
1
it doesn't give me any error ! how did you call
Import
function?– er-sho
Nov 28 '18 at 10:38
it doesn't give me any error ! how did you call
Import
function?– er-sho
Nov 28 '18 at 10:38
1
1
Thank you! I have realized the
Import()
function is reading incorrect values.– Chyu
Nov 28 '18 at 10:58
Thank you! I have realized the
Import()
function is reading incorrect values.– Chyu
Nov 28 '18 at 10:58
you need to pass xml content to
Import
function rather than passing path of xml file– er-sho
Nov 28 '18 at 11:00
you need to pass xml content to
Import
function rather than passing path of xml file– er-sho
Nov 28 '18 at 11:00
What if I want to use path of XML file?
– Chyu
Nov 28 '18 at 11:43
What if I want to use path of XML file?
– Chyu
Nov 28 '18 at 11:43
then you have to fetch content of xml in your
Import
function from path. let me add an solution for you– er-sho
Nov 28 '18 at 11:51
then you have to fetch content of xml in your
Import
function from path. let me add an solution for you– er-sho
Nov 28 '18 at 11:51
|
show 5 more comments
1 Answer
1
active
oldest
votes
Read all your xml content from your path by using File.ReadAllText(fileName)
and pass it to Deserialize
method like.
public static T Import<T>(String fileName) where T : class
{
string xmlData = File.ReadAllText(fileName); //Read xml content from path
YAXSerializer serializer = new YAXSerializer(typeof(T));
return (T)serializer.Deserialize(xmlData); //Pass xml content to Deserialize.
}
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%2f53517120%2fc-sharp-yaxlib-no-elements-with-this-name-found%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
Read all your xml content from your path by using File.ReadAllText(fileName)
and pass it to Deserialize
method like.
public static T Import<T>(String fileName) where T : class
{
string xmlData = File.ReadAllText(fileName); //Read xml content from path
YAXSerializer serializer = new YAXSerializer(typeof(T));
return (T)serializer.Deserialize(xmlData); //Pass xml content to Deserialize.
}
add a comment |
Read all your xml content from your path by using File.ReadAllText(fileName)
and pass it to Deserialize
method like.
public static T Import<T>(String fileName) where T : class
{
string xmlData = File.ReadAllText(fileName); //Read xml content from path
YAXSerializer serializer = new YAXSerializer(typeof(T));
return (T)serializer.Deserialize(xmlData); //Pass xml content to Deserialize.
}
add a comment |
Read all your xml content from your path by using File.ReadAllText(fileName)
and pass it to Deserialize
method like.
public static T Import<T>(String fileName) where T : class
{
string xmlData = File.ReadAllText(fileName); //Read xml content from path
YAXSerializer serializer = new YAXSerializer(typeof(T));
return (T)serializer.Deserialize(xmlData); //Pass xml content to Deserialize.
}
Read all your xml content from your path by using File.ReadAllText(fileName)
and pass it to Deserialize
method like.
public static T Import<T>(String fileName) where T : class
{
string xmlData = File.ReadAllText(fileName); //Read xml content from path
YAXSerializer serializer = new YAXSerializer(typeof(T));
return (T)serializer.Deserialize(xmlData); //Pass xml content to Deserialize.
}
answered Nov 28 '18 at 13:35
er-shoer-sho
6,4752619
6,4752619
add a comment |
add a comment |
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%2f53517120%2fc-sharp-yaxlib-no-elements-with-this-name-found%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
it doesn't give me any error ! how did you call
Import
function?– er-sho
Nov 28 '18 at 10:38
1
Thank you! I have realized the
Import()
function is reading incorrect values.– Chyu
Nov 28 '18 at 10:58
you need to pass xml content to
Import
function rather than passing path of xml file– er-sho
Nov 28 '18 at 11:00
What if I want to use path of XML file?
– Chyu
Nov 28 '18 at 11:43
then you have to fetch content of xml in your
Import
function from path. let me add an solution for you– er-sho
Nov 28 '18 at 11:51