I'm currently studying Berkeley XML DB and got an assignment to write Python script using it. The problem I'm currently facing is to select specific node of container. For example we have container with such information
<root>
<lab>
<name>Lab1</name>
<state>Completed</state>
</lab>
<lab>
<name>Lab3</name>
<state>Not completed</state>
</lab>
</root>
How to select <lab> element with specific <name>? In SQL I'd use WHERE Name='Lab1'. Is there any way to do something like that in XML BDB?
I think you better get old document, copy data, remove document and add new with modified data.
mgr = XmlManager()
uc = mgr.createUpdateContext()
container = mgr.openContainer("labs.dbxml") # Here must be your database name
qc = mgr.createQueryContext()
document = container.getDocument("Lab11")
name = document.getName()
content = document.getContent()
# Change fields here using XPath
container.deleteDocument('La1 1', uc)
container.putDocument(name, content, uc)
Related
I need to write back the annotation status to new pdf with upgraded version. Below is the code I am using for it.
I tried Syncfusion beta version 17.0
PdfLoadedDocument docSource = new PdfLoadedDocument(#"D:\Output1_annotaions.pdf");
PdfLoadedDocument docDestination = new PdfLoadedDocument(#"D:\Output1.pdf");
//Get annotations of first page and read destination of first page
PdfLoadedPage pageDestination = docDestination.Pages[0] as PdfLoadedPage;
PdfLoadedPage pageSource = docSource.Pages[0] as PdfLoadedPage;
//Get annotation objects
PdfLoadedAnnotationCollection annotations = pageSource.Annotations;
//loop through annotation objects
foreach (var item in annotations)
{
pageDestination.Annotations.Add((PdfAnnotation)item);
}
//Save destination document
docDestination.Save(#"D:\Output1.pdf");
//close the documents
docDestination.Close(true);
docSource.Close(true);
I need to write all annotations from one version pdf to newer version pdf along with status nested replies for annotations using syncfusion.
The code example which you have used will not completely import all the annotations present in the source PDF to destination PDF. In order to import annotation from one document to another you may use the below code example:
///Loads the source and destination PDF
PdfLoadedDocument sourcePDF = new PdfLoadedDocument(DataPathBase+"Input.pdf");
PdfLoadedDocument destinationPDF = new PdfLoadedDocument(DataPathBase+"sample.pdf");
string xfdfFilePath = DataPathOutput + "Export_.xfdf";
//Export annotation data to XFDF file
sourcePDF.ExportAnnotations(xfdfFilePath, AnnotationDataFormat.XFdf);
//Import annotation data from XFDF file
destinationPDF.ImportAnnotations(xfdfFilePath, AnnotationDataFormat.XFdf);
//Save imported PDF document
destinationPDF.Save(DataPathOutput+"Output.pdf");
//close the documents
destinationPDF.Close(true);
sourcePDF.Close(true);
You can refer the below UG documentation for the same:
https://help.syncfusion.com/file-formats/pdf/working-with-annotations#importing-annotations-from-xfdf-file
However, using this code does not import the annotations with status properly in some PDF documents. This is confirmed to be defect and the fix for this issue will be included in our 2019 Volume 1 SP1 release which will be available by April 2019 tentatively.
The status of this issue fix can be tracked using following link.
https://www.syncfusion.com/feedback/5430/status-and-layer-is-not-preserved-in-resultant-pdf-while-importing-annotation-from-xfdf
Note: I work for Syncfusion.
Regards,
Dilli babu.
New to couchdb. For this hardcoding the name of Design doc and view name works. Is it possible to give a variable for it?
server = couchdb.Server( url)
db = server['test']
for docid in db.view('Res/res'):
i = docid['key']
The above code works but i want to use this code in a loop
i tried the below code. but its giving me error
for docid in db.view(map.cityname+"/"+city):
I want to parse url attribute from the XML and show image in image control (the one reffered to by the URL) in listbox from the following feed link: http://feeds.bbci.co.uk/news/rss.xml
My code is:
var ComingNewsFromUri = from rss in XElement.Parse(e.Result).Descendants("item")
select new NewsItems
{
Title = rss.Element("title").Value,
PubDate = rss.Element("pubDate").Value,
Description = rss.Element("description").Value
};
For RSS, I would recommend using SyndicationFeed and SyndicationItem....does all the parsing and converting to objects automatically and brilliantly for you.
http://ryanhayes.net/blog/how-to-build-an-rss-feed-reader-in-windows-phone-7part-i-retrieving-parsing-and-displaying-post-titles/
I have an RSS feed app on the store myself using SyndicationFeed and it is very reliable and convenient.
Here is another sample by Microsoft
http://code.msdn.microsoft.com/wpapps/RSS-Reader-Sample-1702775f
Background: Project is a Data Import utility for importing data from tsv files into a EF5 DB through DbContext.
Problem: I need to do a lookup for ForeignKeys while doing the import. I have a way to do that but the retrieval if the ID is not functioning.
So I have a TSV file example will be
Code Name MyFKTableId
codevalue namevalue select * from MyFKTable where Code = 'SE'
So when I process the file and Find a '...Id' column I know I need to do a lookup to find the FK The '...' is always the entity type so this is super simple. The problem I have is that I don't have access to the properties of the results of foundEntity
string childEntity = column.Substring(0, column.Length - 2);
DbEntityEntry recordType = myContext.Entry(childEntity.GetEntityOfReflectedType());
DbSqlQuery foundEntity = myContext.Set(recordType.Entity.GetType()).SqlQuery(dr[column])
Any suggestion would be appreciated. I need to keep this generic so we can't use known type casting. The Id Property accessible from IBaseEntity so I can cast that, but all other entity types must be not be fixed
Note: The SQL in the MyFKTableId value is not a requirement. If there is a better option allowing to get away from SqlQuery() I would be open to suggestions.
SOLVED:
Ok What I did was create a Class called IdClass that only has a Guid Property for Id. Modified my sql to only return the Id. Then implemented the SqlQuery(sql) call on the Database rather than the Set([Type]).SqlQuery(sql) like so.
IdClass x = ImportFactory.AuthoringContext.Database.SqlQuery<IdClass>(sql).FirstOrDefault();
SOLVED:
Ok What I did was create a Class called IdClass that only has a Guid Property for Id. Modified my sql to only return the Id. Then implemented the SqlQuery(sql) call on the Database rather than the Set([Type]).SqlQuery(sql) like so.
IdClass x = ImportFactory.AuthoringContext.Database.SqlQuery<IdClass>(sql).FirstOrDefault();
I need to parse an XLIFF file using C#, but I'm having some trouble. These files are fairly complex, containing a huge amount of nodes.
Basically, all I need to do is read the source node from each trans-unit node, do some processing on it, and insert the processed text into the corresponding target node (which will always be present, but empty).
An example of one of the nodes I need to parse would be (the whole file may contain 100s of these):
<trans-unit id="0000000002" datatype="text" restype="string">
<source>Windows Update is not installed</source>
<target/>
<iws:segment-metadata tm_score="0.00" ws_word_count="6" max_segment_length="0">
<iws:status target_content="placeholders_only"/>
</iws:segment-metadata>
<iws:boundary-seg sequence="bs20721"/>
<iws:markup-seg sequence="0000000001">
</trans-unit>
The trans-unit nodes can be buried deep in the files, the header section contains a lot of data. I'd like to use LINQ to XML to read the data, but I'm not having any luck getting it to work. Here's my current code (just trying to read and output the source nodes from the file:
XDocument doc = XDocument.Load(path);
Console.WriteLine("Before loop");
foreach (var transUnitNode in doc.Descendants("trans-unit"))
{
Console.WriteLine("In loop");
XElement sourceNode = transUnitNode.Element("source");
XElement targetNode = transUnitNode.Element("target");
Console.WriteLine("Source: " + sourceNode.Value);
}
I never see 'In loop' and I don't know why, can someone tell me what I'm doing wrong here, or suggest a better way to achieve what I'm trying to do here?
Thanks.
Try
XNamespace df = doc.Root.Name.Namespace;
foreach (XElement transUnitNode in doc.Descendants(df + "trans-unit"))
{
XElement sourceNode = transUnitNode.Element(df + "source");
// and so one, use the df namespace object to qualify any elements names
}
See also http://msdn.microsoft.com/en-us/library/bb387093.aspx.