I need to generate classes from xml that doesn't provide a schema. I understand this is near useless, but the fact is we have xml, it's structured, and we should be able to create a model from the xml. In the past I've done it by hand, but the current xml documents I am working with are quite large and my time would probably be better spent building something that does what I need. But, I am guessing it has already been done, and I just can't find it.
我需要从不提供模式的xml生成类。我知道这几乎没用,但事实是我们有xml,它是结构化的,我们应该能够从xml创建一个模型。在过去,我是手工完成的,但是我正在处理的当前xml文档非常大,我的时间最好花在构建一些能够满足我需要的东西上。但是,我猜它已经完成了,我就是找不到。
Any pointers?
指针吗?
3 个解决方案
#1
56
There are many tools available (a quick google search should fetch you some) that can generate XSD from XML assuming string type for almost everything. You should be able to use that XSD to run JAXB to get classes.
有许多可用的工具(快速的谷歌搜索应该可以为您获取一些),它们可以为几乎所有的东西生成XML假设字符串类型的XSD。您应该能够使用该XSD运行JAXB以获取类。
Here's an online tool that lets you do that.
这里有一个在线工具可以让你做到这一点。
And here is a screen cap:
这是一个屏幕盖:
#2
8
From your xml file, you can create a XML Schema Definition (XSD) file. Once you have the XSD, you'll be able to generate the code, need it be for java, C#, C++, or all of the above.
从xml文件中,可以创建一个xml模式定义(XSD)文件。一旦您拥有了XSD,您将能够生成代码,需要它用于java、c#、c++或以上所有代码。
If you have Visual Studio, you can use xsd.exe to generate the XSD file.
如果有Visual Studio,可以使用xsd。生成XSD文件的exe。
References:
引用:
-
www.xmlforasp.net/CodeBank/System_Xml_Schema/BuildSchema/BuildXMLSchema.aspx
www.xmlforasp.net/CodeBank/System_Xml_Schema/BuildSchema/BuildXMLSchema.aspx
-
msdn.microsoft.com/en-us/library/x6c1kb0s(v=vs.71).aspx
msdn.microsoft.com/en-us/library/x6c1kb0s(v = vs.71). aspx
-
Command Syntax: xsd file.xml [/outputdir:directory]
命令语法:xsd文件。xml[/ outputdir目录):
-
so "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\xsd.exe" example.xml yields a example.xsd file in the same directory as the xml file.
所以“C:\ Program Files \ Microsoft Windows sdk \ \ v6.0A \ Bin \ x64 \ xsd。exe”的例子。xml收益率的例子。与xml文件位于同一目录中的xsd文件。
XSD to Java: Reference:
XSD到Java:参考:
- http://www.javaworld.com/javaworld/jw-06-2006/jw-0626-jaxb.html
- http://www.javaworld.com/javaworld/jw - 06 - 2006/jw - 0626 jaxb.html
- Command Syntax: xjc your.xsd -p com.example.package -d src/generatedOutputDirectory
- 命令语法:xjc你。com . example。xsd - p包- d src / generatedOutputDirectory
XSD to C++: References:
c++ XSD:引用:
- *.com/questions/445905/xml-schema-to-c-classes
- *.com/questions/445905/xml-schema-to-c-classes
- www.codesynthesis.com/products/xsd/
- www.codesynthesis.com/products/xsd/
XSD to C#: Reference:
c# XSD:参考:
- quickstart.developerfusion.co.uk/quickstart/howto/doc/xmlserialization/XSDToCls.aspx
- quickstart.developerfusion.co.uk /快速入门/ howto / doc / xmlserialization / XSDToCls.aspx
- Command Syntax: "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\xsd.exe" -c -l:c# -n:SomeNameSpace example.xsd
- 命令语法:“C:\程序文件\ microsoftsdks \Windows\v6.0A\Bin\x64\xsd。exe" -c -l:c# -n: som珐琅空间示例。xsd
#3
1
If the XML was created by JAXB, it can easily be converted back into objects. There's a tutorial over at oracle which illustrates one way to do this. Spring framework offers similiar features using JAXB which are very conveniant.
如果XML是由JAXB创建的,那么可以很容易地将其转换回对象。在oracle有一个教程,说明了一种方法。Spring框架使用JAXB提供了非常方便的similiar特性。
#1
56
There are many tools available (a quick google search should fetch you some) that can generate XSD from XML assuming string type for almost everything. You should be able to use that XSD to run JAXB to get classes.
有许多可用的工具(快速的谷歌搜索应该可以为您获取一些),它们可以为几乎所有的东西生成XML假设字符串类型的XSD。您应该能够使用该XSD运行JAXB以获取类。
Here's an online tool that lets you do that.
这里有一个在线工具可以让你做到这一点。
And here is a screen cap:
这是一个屏幕盖:
#2
8
From your xml file, you can create a XML Schema Definition (XSD) file. Once you have the XSD, you'll be able to generate the code, need it be for java, C#, C++, or all of the above.
从xml文件中,可以创建一个xml模式定义(XSD)文件。一旦您拥有了XSD,您将能够生成代码,需要它用于java、c#、c++或以上所有代码。
If you have Visual Studio, you can use xsd.exe to generate the XSD file.
如果有Visual Studio,可以使用xsd。生成XSD文件的exe。
References:
引用:
-
www.xmlforasp.net/CodeBank/System_Xml_Schema/BuildSchema/BuildXMLSchema.aspx
www.xmlforasp.net/CodeBank/System_Xml_Schema/BuildSchema/BuildXMLSchema.aspx
-
msdn.microsoft.com/en-us/library/x6c1kb0s(v=vs.71).aspx
msdn.microsoft.com/en-us/library/x6c1kb0s(v = vs.71). aspx
-
Command Syntax: xsd file.xml [/outputdir:directory]
命令语法:xsd文件。xml[/ outputdir目录):
-
so "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\xsd.exe" example.xml yields a example.xsd file in the same directory as the xml file.
所以“C:\ Program Files \ Microsoft Windows sdk \ \ v6.0A \ Bin \ x64 \ xsd。exe”的例子。xml收益率的例子。与xml文件位于同一目录中的xsd文件。
XSD to Java: Reference:
XSD到Java:参考:
- http://www.javaworld.com/javaworld/jw-06-2006/jw-0626-jaxb.html
- http://www.javaworld.com/javaworld/jw - 06 - 2006/jw - 0626 jaxb.html
- Command Syntax: xjc your.xsd -p com.example.package -d src/generatedOutputDirectory
- 命令语法:xjc你。com . example。xsd - p包- d src / generatedOutputDirectory
XSD to C++: References:
c++ XSD:引用:
- *.com/questions/445905/xml-schema-to-c-classes
- *.com/questions/445905/xml-schema-to-c-classes
- www.codesynthesis.com/products/xsd/
- www.codesynthesis.com/products/xsd/
XSD to C#: Reference:
c# XSD:参考:
- quickstart.developerfusion.co.uk/quickstart/howto/doc/xmlserialization/XSDToCls.aspx
- quickstart.developerfusion.co.uk /快速入门/ howto / doc / xmlserialization / XSDToCls.aspx
- Command Syntax: "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\xsd.exe" -c -l:c# -n:SomeNameSpace example.xsd
- 命令语法:“C:\程序文件\ microsoftsdks \Windows\v6.0A\Bin\x64\xsd。exe" -c -l:c# -n: som珐琅空间示例。xsd
#3
1
If the XML was created by JAXB, it can easily be converted back into objects. There's a tutorial over at oracle which illustrates one way to do this. Spring framework offers similiar features using JAXB which are very conveniant.
如果XML是由JAXB创建的,那么可以很容易地将其转换回对象。在oracle有一个教程,说明了一种方法。Spring框架使用JAXB提供了非常方便的similiar特性。