I want to modify an XML file which has a very complicated structure something like
<root>
<a></a>
<b></b>
<c></c>
<d>
<e>text</e>
<f>text</f>
<d>
<d>
....
</root>
I tried to use tinyxml and it is good but there are some comments in the source xml file that I want to keep so I thought may be dealing with the file as mere text can be a good idea, however the string functions in c++ are crippling me because I'll have to search and replace, any ideas?
Note:There are no attributes in the XML, just values between the tags.
I don't know if using a third party library is off the table for parsing but I've been using this XSD parser which allows you to serialize XML files to memory. You are then free to edit and/or read the values at their node locations and then write the file back out.
This, to me, at least, is significantly simpler than generating a custom parser for each type of XML input.
Related
I know that the input of an XSLT processor is a source XML document that will be transformed into a target XML document.
In my case, I haven't a source XML document but I have a source XML-SCHEMA and I want to know through the XSLT document information about the mappings between the source XML-SCHEMA and the target one.
Thus, I have the idea of executing or maybe parsing the XSLT on the source XML-SCHEMA in order to get this information.
I'm really confused about the difference between execute and parse an XSLT document.
I think that to execute an XSLT document, an XSLT processor firstly parses it to transform it to another internal representation.
What is this internal representation??
I really need your help
I'm really confused about the difference between execute and parse an
XSLT document.
To parse a language, including XML, is to analyse it into parts.
To execute a language, including XSLT, is to perform the instructions specified by the language.
It does not make sense to talk about executing XML because XML itself specifies no instruction.
It does make sense to talk about validating XML against the grammar given by its XSD.
I think that to execute an XSLT document, an XSLT processor firstly
parses it to transform it to another internal representation. What is
this internal representation??
You do not need to know an XSLT processor's internal representation because that is an implementation detail.
You do need to know that an XSLT processor parses an input XML document, executes an XSLT transformation, and generates output. (It also parses the XML that represents the XSLT, but that's beside the point.)
The input XML document typically is not an XSD. You might want to consider the XSD associated with the input XML document in order to anticipate allowed input variations. In rare circumstances you might want to transform the XSD itself in some way, and you can do so since an XSD is represented in XML. In other rare circumstances, you might want to transform XSLT itself in some way, and you can do so since XSLT is also represented in XML. But, normally, the input to an XSLT transformation is a mundane XML document instance, not an XSD, and not other XSLT.
I have a char array and the text actually looks like XML:
<root>
<number>1</number>
<counter>2</counter>
<lastNumber>3</lastNumber>
</root>
I need to get these values and store them to variables so I can work with them.
Any idea how to do that?
Thank you
You could use TinyXML, to parse the file. http://www.grinninglizard.com/tinyxml/
Its a open source library to parse XML files in C++.
You should formulate a better question, but the general idea is clear and so I suggest to use a library such as boost::spirit or, if you can arrange your data in a different way, you can use boost::config which is probably a much simpler approach and here is an example .
I have an configuration xml file which has some values like
<config>
<map>100,1,200,1</map>
<image>abc.bmp</image>
.
.
.
.
</config>
etc.
I imported the file read line by line all are done. I have to validate the fields in file. Like
1. <map> " "</map> is not empty,no junk value,
2. <image>abc**,**bmp</im*E*ge> (spelling mistake)
3. <image>abc.bmp </config> ( missing tags)
I have to develop a unique algorithm so that cant use libs . Is there any idea rather than loading and checking every one character by character?
I'd recommend to use a 3rd party library to implement XML parsing. Getting all the details and pitfalls of XML parsing correct is much harder than you might think.
Your points 2. and 3. will be supported well by any complete XML parser. Point 1. will need either XSL schema definition and a parser that supports schema validation, or you'll need to provide extra validation code manually.
If you're concerned about impact (code/memory usage) you should refer to these lightweight C/C++ XML parsers:
C++ expat (can be used in commercial projects)
TinyXml (can be used in commercial projects)
Other XML parsers
POCO XML
Xerces C++ (provides XSL Schema validation)
I am writing a large xml file in C++. What i need is the capability to construct dom trees of records in chunks and flush the chunks to disk. So for example,
-----------chunk create-----
<record>data<record>
<record>data<record>
<record>data<record>
<record>data<record>
-----------chunk flush--------
Also, a single line should contain one full record as shown above. what i dont want is printing in format shown below
<record>
data
</record>
Which library would allow both the above functionality?
may be you can try TinyXML : http://sourceforge.net/projects/tinyxml/
i use RapidXml.
i have complex xslt that formats xml to html
now i need to be able to create xsl fo out of it
what is the best way to do it ?
Here is some ineresting article for you
http://www-128.ibm.com/developerworks/library/x-xslfo2app/
Also you can try next library (I dont't remember, probably it can creat fo files from xslt+xml):
http://www.codeproject.com/KB/dotnet/nfop.aspx
I had a similar requirement, and I did some research, but didn't find a reliable XHTML to FO transformer. There may be one, but there comes a point in some web searches when you have to give up and roll your own.
Instead I took the XML to HTML transformer I had already written and changed it to output FO.
This is a much simpler proposition that a full blown XHTML to FO transformer.
Whilst your details will differ, most structures in HTML have analogues in FO, so you can normally decide what FO construct to use in replacing HTML in your transform fairly easily.
I did this incrementally. If you start with the transform producing the outline of an FO document, and most of your XML being ignored in the transform, you can then build up the output in a measured fashion.