Removing specific element from xml using sax with xerces library in c++ - c++

My problem is that I want to remove lastfiles and all it's child element using sax with the API of Xerces in c++ language??
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE config>
<config datecreated="20011210">
<user>
John Smith
</user>
<login>jsmith</login>
<password>topsecret</password>
<lastfiles>
<lastfile timestamp="20011210T1002">accounts.txt</lastfile>
<lastfile timestamp="20011190T1132">/home/jsmith/docs/letter.doc</lastfile>
</lastfiles>
</config>

Related

Delete comments from xml file while parsing it using libxml

Following is the XML file with one of its node(i.e. <date>) being commented.
<?xml version="1.0"?>
<story>
<info>
<author>Abc Xyz</author>
<!--<date>June 2, 2017</date> -->
<keyword>example keyword</keyword>
</info>
</story>
What I want is to remove that commented line/node completely from the XML file using libxml library and it should look as below:
<?xml version="1.0"?>
<story>
<info>
<author>Abc Xyz</author>
<keyword>example keyword</keyword>
</info>
</story>
I also referred the libxml documentation but that didn't helped me much with the "comment/s" in XML file.
I tried in a different way and it worked. Looks like using xmlreader for modifying the xml will not help much, instead I did xmlReadMemory(), then while parsing did following check:
if(node->type == XML_COMMENT_NODE){ //node is of type xmlNodePtr
xmlUnlinkNode(node);
xmlFreeNode(node);
}
And finally xmlDocDumpFormatMemory() to store the modified xml in xmlbuffer.
You can use NodeType() while parsing the xml and check for each node if it’s a comment (8 means comment, see here: http://xmlsoft.org/xmlreader.html#Extracting) and then remove it with xmlUnlinkNode() and xmlFreeNode().

remove namespaces of multiple tags

i've just learned some xslt langauge and i have a problem. I'm trying to remove this namespace without success.
Original xml:
<?xml version="1.0" encoding="UTF-8"?>
<file_information xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.chellodmc.com/files/dmc_media_delivery.xsd" xsi:schemaLocation="http://www.chellodmc.com/file0073/dmc_media_delivery.xsd http://www.chellodmc.com/files/dmc_media_delivery.xsd">
<asset_data soa:23946923649236489>
<upn>TEST_Sintec_HD</upn>
<title>NLD_NGC_C_Man United - Chelsea - Sunday #17.00</title>
<version>High Definition</version>
<duration>00:30</duration>
<tc_in>23:00:00:00</tc_in>
<tc_out>23:00:30:00</tc_out>
<aspect_ratio>16X9</aspect_ratio>
<segment>
<sequence>1</sequence>
<tc_in>23:00:00:00</tc_in>
<tc_out>23:00:30:00</tc_out>
<comment></comment>
</segment>
</asset_data>
</file_information>
Expected output xml:
<?xml version="1.0" encoding="UTF-8"?>
<file_information>
<asset_data>
<upn>TEST_Sintec_HD</upn>
<title>NLD_NGC_C_Man United - Chelsea - Sunday #17.00</title>
<version>High Definition</version>
<duration>00:30</duration>
<tc_in>23:00:00:00</tc_in>
<tc_out>23:00:30:00</tc_out>
<aspect_ratio>16X9</aspect_ratio>
<segment>
<sequence>1</sequence>
<tc_in>23:00:00:00</tc_in>
<tc_out>23:00:30:00</tc_out>
<comment></comment>
</segment>
</asset_data>
</file_information>
what would be your suggestion?
Many thanks!

apigee policy error - java.lang.String cannot be cast to com.apigee.flow.message.Message

I am trying to transform a JSON response from a target end point into soap message. I have 2 policies in the post flow.
JSONTOXML - If I disable xsltransform I see the xml result so this work.
xsltransform - this just point to my xsltransform file which has the template and dynamic content supposed to come from the xml from step 1.
Both source and output are set to "response" but it looks like it failed to cast in step 2. What should I make step 2 to pick up the xml and apply the xsl? How else can I do this? Thanks
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONToXML async="false" continueOnError="false" enabled="true" name="jsontoxml-2">
<DisplayName>JSONtoXML-2</DisplayName>
<FaultRules/>
<Properties/>
<Options>
<NullValue>NULL</NullValue>
<NamespaceBlockName>#namespaces</NamespaceBlockName>
<DefaultNamespaceNodeName>$default</DefaultNamespaceNodeName>
<NamespaceSeparator>:</NamespaceSeparator>
<TextNodeName>#text</TextNodeName>
<AttributeBlockName>#attrs</AttributeBlockName>
<AttributePrefix>#</AttributePrefix>
<InvalidCharsReplacement>_</InvalidCharsReplacement>
<ObjectRootElementName>Root</ObjectRootElementName>
<ArrayRootElementName>Array</ArrayRootElementName>
<ArrayItemElementName>Item</ArrayItemElementName>
</Options>
<OutputVariable>response</OutputVariable>
<Source>response</Source>
</JSONToXML>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XSL async="false" continueOnError="false" enabled="true" name="xsltransform-1">
<DisplayName>XSLTransform-1</DisplayName>
<FaultRules/>
<Properties/>
<Source>response</Source>
<ResourceURL>xsl://xsltransform-1</ResourceURL>
<Parameters ignoreUnresolvedVariables="true"/>
<OutputVariable>response</OutputVariable>
</XSL>
OutputVariable cannot be set to 'response'.
Try removing the 'OutputVariable' line, or leaving it empty. Removing it, should cause the output to go to the response payload.
In other words, try this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XSL async="false" continueOnError="false" enabled="true" name="xsltransform-1">
<DisplayName>XSLTransform-1</DisplayName>
<FaultRules/>
<Properties/>
<Source>response</Source>
<ResourceURL>xsl://xsltransform-1</ResourceURL>
<Parameters ignoreUnresolvedVariables="true"/>
</XSL>
Is this always the case? Can OutputVariable never be set on response?

How to create news ticker XML file in Joomla?

I got this extensions and all I want to know is how I am able to get the news ticker from XML file and how should I create this file?
I tried this one and it is not working.
XML file
http://www.4shared.com/document/uNJ9sdmD/newsxml.html
Extension link
http://extensions.joomla.org/extensions/news-display/articles-display/news-tickers-a-scrollers/6633?qh=YToxMDp7aTowO3M6NDoibmV3cyI7aToxO3M6MzoibmV3IjtpOjI7czo3OiJuZXduZXNzIjtpOjM7czo1OiInbmV3cyI7aTo0O3M6NToibmV3J3MiO2k6NTtzOjY6Im5ld2VseSI7aTo2O3M6NToibmV3cyciO2k6NztzOjY6Im5ld3MnLCI7aTo4O3M6NjoiJ25ldycsIjtpOjk7czo2OiInbmV3cyciO30%3D
First create the XML file and insert it in the correct directory
/modules/mod_highlighter_gk4/xml --> this is where you need to insert the file.
You can find a sample XML file named Sample on that folder which tells you exactly how to format you XML file. It's something like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<highlighter>
<item>
<title>Title 1</title>
<desc>Item description 1</desc>
<link>http://item1.title.com</link>
</item>
<item>
<title>Title 1</title>
<desc>Item description 1</desc>
<link>http://item1.title.com</link>
</item>
On the module itself first make sure you select the XML file on the "data source".
Then on the XML File option put the name of the XML File you created and it should work.
You can find more info from their website as well.
http://www.gavick.com/forums/highlighter.html

XercesDOMParser and XIncludes

I am attempting to get xincludes working in an existing system that uses a XercesDOMParser in xercesc to parse incoming xml from a client. I am working with Apache Xercesc v3.0.1, and the incoming XML, read from an input stream, is:
<?xml version="1.0" encoding="UTF-8"?>
<VisionServer xmlns:xi="http://www.w3.org/2001/XInclude">
<CompositeObject>
<xi:include href="testguioutput.xml" />
while testguioutput.xml contains
<?xml version="1.0" encoding="UTF-8"?>
<GUIOutput>
<Input>Input</Input>
<Title>IDC2_1</Title>
</GUIOutput>
The existing code uses a wrapper around a XercesDOMParser to parse the XML as it comes in, and after using setDoNamespaces and setDoXInclude to true, it is attempting to parse the XInclude, but I get a persistent "Fatal: include failed and no fallback element found in document '{0}'" error, no matter where in the directory structure I put testguioutput.xml.
I am working under visualstudio 2008, my working directory is default, and running out of /project/debug, but the include fails whether the target file is in /project/ or /project/debug/.
I was able to expand the xinclude tags using the XInclude.exe sample application that is included with the Xerces application. To do this, I created two files using your files above:
test1.xml:
<?xml version="1.0" encoding="UTF-8"?>
<VisionServer xmlns:xi="http://www.w3.org/2001/XInclude">
<CompositeObject>
<xi:include href="test2.xml"/>
</CompositeObject>
</VisionServer>
test2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<GUIOutput>
<Input>Input</Input>
<Title>IDC2_1</Title>
</GUIOutput>
At the command line I executed:
"XInclude.exe test1.xml test1_expanded.xml" without quotes.
The resulting test1_expanded.xml file:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<VisionServer xmlns="" xmlns:xi="http://www.w3.org/2001/XInclude">
<CompositeObject>
<GUIOutput xml:base="test2.xml">
<Input>Input</Input>
<Title>IDC2_1</Title>
</GUIOutput>
</CompositeObject>
</VisionServer>