I have a "new_xml.xml" file as follows:
<?xml version="1.0" standalone="no"?>
<people>
<husband employed = "Yes">
<name>MArk</name>
<age>45</age>
<wife>
<wname>jenet</wname>
<age>65</age>
</wife>
</husband>
</people>
Now, i want to add following line at the top of "new_xml.xml":
<!DOCTYPE people SYSTEM "new_xmll.dtd">
So, suggest me how can i edit "new_xml.xml" using c++ and add above line into it
You can just open a new file, write the string and the Content of the old file.
ifstream oldXML("path/to/old/xml");
ofstream newXML("path/to/new/xml");
newXML<<"<!DOCTYPE people SYSTEM \"new_xmll.dtd\">"<<endl; //Write first line
newXML<<oldFile; //Copy Content of old file
You can also use a XML library if you want to Change any XML values. I like tinyxml a lot
Then probably TinyXML or MSXML would be interesting for you.
try to use cycle with eof and read each line with getline(), when you find your line just add it.
Related
I have an existing custom xml file for which I need to add a tag basically append it to the end of root node. But as the xml format will not be changed it can be safely assumed that parsing is not required and only need to add this tag in the end of the file.
XML format:
<links>
...
...
<url type="search">www.google.com</url>
</links>
In the above xml file, I would like to add the tag.
File operation suggests we cannot add in the middle of the file. Can anyone suggest other approaches?
"Safely" is always relative. You can never "safely" assume that you can process XML without parsing unless you are 100% in control of the process that generates the XML, and are confident you will remain so.
And if you are in control of the XML, then I would suggest maintaining it as two files: a content.xml file that holds everything except the root element, and a wrapper.xml file that references content.xml as an external entity:
<!DOCTYPE links [
<!ENTITY e SYSTEM "content.xml">
]>
<links>&e;</links>
and then you can use a normal file append operation on content.xml to add to the content.
I need to add multiple languages to our Qt-based products. I did some googles and got some ideas. But, I could not find one answer: How does the '.ts' file know which language is for?
For examples, in the sample project: i18n.
I deleted the original 'i18n_zh.ts' file and used 'lupdate' to create a new 'i18n_zh.ts' file. I then looked at the contents of the new file. It has this line:
TS version="2.1" language="zh_CN"
I then used 'linguist' tool to open the new 'i18n_zh.ts' file and found out Qt knew it was Chinese translation.
How did Qt know it is Chinese? Where is the mapping table? Does '_zh' in the file name hint anything?
Some contents in the new 'i18n_zh.ts' file:
?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>MainWindow</name>
<message>
<location filename="../languagechooser.cpp" line="176"/>
<location filename="../mainwindow.cpp" line="85"/>
<source>English</source>
<translation type="unfinished"></translation>
</message>
Effectively, lupdate parses the name file to get the language. It uses a similar method to the one by QLocale.
Once you have the locale, you can use methods like QLocale::nativeLanguageName to get the language name (in this case the language name in that language).
Just for completeness, QTranslator also uses such filename suffixes to find the correct .qm file to load for current locale. More info here.
For additional information, a good start point is the own Qt's wiki page about multi-language applications.
The first line in the ui file reads as follows:
Any idea what is the issue with this line, and how to overcome this problem?
Your issue is the missing space. I have tried the following line in my QtDesigner:
<?xml version="1.0"encoding="UTF-8"?>
It did not work, but when I modified it to contain the space after the quote and before the next attribute like this:
<?xml version="1.0" encoding="UTF-8"?>
The designer could load it just fine.
You probably accidentally made this mistake while manually viewing the file.
Admittedly, QtDesigner is reporting the error weird because if you look up an xml validation program (xml lint, www.xmlvalidation.com) for your content, they will provide more accurate error diagnotic as follows:
Errors in the XML document:
1: 36 White space is required before the encoding pseudo attribute in the XML declaration.
After creating the xml file with QXmlStreamWriter, I am trying to add each modification of parameters at the end of the file, and I do startDocument in each addition, how can I read an XML file that contains many of
Help please please !
You will have to manually convert the document from your custom format of multiple-concatenated XML files back into real, stand-alone XML files, then pass it into the parser once it is in fact valid XML data.
i have a xsl file which is containing some contents for displaying.This contents gets changed often. so each time have to modify the xsl file.
So thought of moving the content to a text ot properties file so that just changing this will be fine.
can anybody tell me how to move just the contents to a text file and access it using xsl file.
Thanks in advance.
Why use a text file? Surely XML would be better?
An XSLT stylesheet can read a second input document using document('strings.xml'). Then you can access strings as for example
<xsl:value-of select="document('strings.xml')//string[#id='msg012']"/>
where the file has a format like
<strings>
<string id='msg012'>This is one of the strings to include</string>
</strings>
In XSLT 2.0 you can wrap the access logic into a function so the call just becomes
<xsl:value-of select="my:string('msg012')"/>