This is follow-up to:
using xslt to create an xml file in c
<element1 type="type1" name="value1">
<start play="no"/>
<element2 aaa="AAA"/>
<element2 bbb="BBB"/>
<element3 ccc="CCC">
<element4/><!-- play="no"/>-->
</element3>
</element1>
Lets say I get this xml file, how do I read individual nodes? I mean, not all nodes are mandatory. Do I need to go though all nodes via "libxml2" or something similar and read its values? OR I can use some sort of schema to define what my xml can look like? What is a better way of dealing with this problem?
A schema is never a bad idea, however it won't help you read the xml as such. All schema would do given you validate the xml against it is tell you it follows whatever rules are in there.
For the rest of it, a quick search on here would have found this. How can libxml2 be used to parse data from XML?
Related
I have a file ontobible.owl. how to extract that file and then save data to mysql (because I want display data from ontobible.owl in website). can anyone help me?
edited:
here is my ontobible.owl file (https://teamtrainit.com/ontobible.owl)
i've try open ontobible.owl with sublime text 3 and contains like this
<Verse rdf:about="http://www.semanticweb.org/budsus/ontologies/2021/7/ontobible#HOS5_2">
<verseID>HOS5_2</verseID>
<verse_text>And the revolters are profound to make slaughter, though I have been a rebuker of them all.</verse_text>
</Verse>
<Verse rdf:about="http://www.semanticweb.org/budsus/ontologies/2021/7/ontobible#2CH2_1">
<hasPerson rdf:resource="http://semanticbible.org/ns/2006/NTNames#god_1324"/>
<hasPerson rdf:resource="http://www.co-ode.org/roberts/family-tree.owl#solomon_2762"/>
<verseID>2CH2_1</verseID>
<verse_text>And Solomon determined to build an house for the name of the LORD, and an house for his kingdom.</verse_text>
</Verse>
how to convert that xml tag to array or json so I cant save it to mysql database
you have several options for extracting data from owl
use owl-api and write java code (i think owl api is accessible in other languages) to extract data and pack it in the format you need. also you can use sparql queries for extracting data via jena api
install protege, open your file in protege and save it in format json-dl. this format is very similar to the regular json and you can easily transform it for your needs
install fuseki server, add your file and using sparql queries extract data from there
i think that the second option is the easiest for start if you don't want to write queries or code and it won't take long
Recently I got a requirement to read a file and insert those records into a DB. But, when I looked at the file it is not consistent, and the source team is not in a position to alter it in any way. So, is there a way to read it?
Example of a File:
Record1,Record2,Record3,Record4
Record1,Record2,Record3,Record4
Record1,Record2
Record1,Record2,Record3,Record4
Record1,Record2,Record3,Record4
Record1,Record2
Record1,Record2,Record3,Record4
Any inputs will be appreciated.
Regards,
Vishnu.
If I understand correctly, you have a comma-separated list of values and each new line forms a dataset.
You can use MFL Format Builder with delimiter as a comma and generate a standardized XML document out of your data.
This link has a good tutorial to get you started.
I've been searching to no avail for a set of routines to do conversion between JSON and XML. I have found such routines in Javascript, Java, PHP, and Python, but not in C or C++.
FWIW, my json library is json-spirit. I am currently processing JSON, and would like to add XML support via a conversion layer (convert incoming messages from XML to JSON, process them, convert results back to XML, and them out).
Does anyone have any pointers?
I've also seen a number of references to badgerfish, rayfish, rabbitfish... encoding conventions, but they seem to point to dead URLs. Is there a reference somewhere which describes each convention?
And yes, I've checked on json.org.
By far, the only specifically designed C++ library that directly converts XML to JSON I found on the Internet is xml2json: https://github.com/Cheedoong/xml2json
You can also convert JSON to XML if following the same rules.
Boost.PropertyTree handles both JSON and XML. There are some quirks in their implementations, so it wouldn't be a direct transformation, but it shouldn't need much work to adapt a property_tree between JSON and XML.
You could write a xslt for your xml document to convert to json. But I see no standard jslt for converting json.
Earlier,In TSQL we have an XML column to store the html data with xml serialization.
But now we think to keep the html content in CDATA region.
How can I convert the existing xml serialized content to the corresponding html content?
e.g. XML serialized column data : <Node Txt="<b>bold text</b>" />
Expected corresponding transform : <Node><![CDATA[<b>bold text</b>]]></Node>
The above transformation is expected to be carried over by sql script.
I think of a solution to replace all those 5 xml special chars corresponding replacement characters (&,<,>,",etc.). But I dont think string manipulation may work in xml to html transformation.
Any cleaner way or idea to transform those existing xml to html data?
Maybe use the PHP function htmlspecialchars to translate it. If it's a one time thing, this shouldn't be too much trouble for you.
If not, you could code something up using SQL string functions. http://msdn.microsoft.com/en-us/library/ms186862.aspx
I need to extract url from XML response. Here is the XML response:
<cloud xmlns:xlink="http://www.w3.org/1999/xlink">
<rootContainer xlink:href="https://api.example.net/v2/bucket/92FBC29C-344C-99CF-827E-1B5586A7F8E3"
xlink:type="simple"/>
</cloud>
I'm using C to write regex. Need help.
my output needs to be https://api.example.net/v2/bucket/92FBC29C-344C-99CF-827E-1B5586A7F8E3
You shouldn't. If you have the option, you should use an XML processor for any number or reasons.
But if you must, you can do something like "rootContainer.xlink:href=\"([^\"]+)\" Syntax may vary depending on what regex library you're using - there isn't a single "regex" syntax.